【python入门学习】在pycharm中安装pygame和matploylib

在pycharm中安装pygame和matploylib

之前介绍了在windows系统中用pip安装pygame和matplotlib,但如果不在pycharm中导入该库的话,也无法在pycharm中使用该库。这里将介绍怎么在pycharm导入第三方库。

在pycharm导入第三方库

  1. 打开pycharm,点击File,点击settings…
    在这里插入图片描述
  2. 找到 project:data_visualization 下的 project interpreter ,点击图中_右上角_的加号。(这里的data_visualization是我自己建的项目名称,不同的项目名称不一样)
    在这里插入图片描述
  3. 搜索pygame和matplotlib,选中后,点击_左下方_的 install package ,耐心等待即可。在这里插入图片描述

温馨提示:有时候可能安装不成功,多试几次,大的库安装较慢,喝杯咖啡等下看。

  1. 检验安装成果
    观察已安装包,发现所需的库在里面。在这里插入图片描述
    现在,我们可以写代码来试一下。下图中,编辑框中没有出现红线提示,并且运行没有报错,说明pycharm导入库成功。
    在这里插入图片描述

在pycharm中导入库,但未用pip installxxx安装库

如果在cmd未用指令pip install xxx安装xxx库,但是在pycharm成功导入了,在cmd中使用import xxx也会报错。
例如,我在pycharm中导入了pygame_ai,但未使用指令pip install pygame_ai安装,会出现以下报错:

C:\Users\dell>python
	Python 3.8.3 (tags/v3.8.3:6f8c832, May 13 2020, 22:20:19) [MSC v.1925 32 bit (Intel)] on win32
	Type "help", "copyright", "credits" or "license" for more information.
	>>> import pygame_ai
	Traceback (most recent call last):
	  File "<stdin>", line 1, in <module>
	ModuleNotFoundError: No module named 'pygame_ai'

但如果再用pip install pygame_ai安装后,就可以在cmd使用。

C:\Users\dell>pip install pygame_ai
	Collecting pygame_ai
	  Using cached pygame_ai-0.1.2-py3-none-any.whl (30 kB)
	Requirement already satisfied: pygame<2 in e:\python\lib\site-packages (from pygame_ai) (1.9.6)
	Installing collected packages: pygame-ai
	Successfully installed pygame-ai-0.1.2
	
	C:\Users\dell>python
	Python 3.8.3 (tags/v3.8.3:6f8c832, May 13 2020, 22:20:19) [MSC v.1925 32 bit (Intel)] on win32
	Type "help", "copyright", "credits" or "license" for more information.
	>>> import pygame_ai
	pygame 1.9.6
	Hello from the pygame community. https://www.pygame.org/contribute.html
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值