简体   繁体   English

即使安装了 pygame 也无法导入

[英]Can't import pygame even though it is installed

I go into IDLE and type in import pygame to the shell and it gives me an error.我 go 进入 IDLE 并输入 import pygame 到 shell ,它给了我一个错误。 Then I go into a new program and type in import pygame and I get the same error.然后我 go 进入一个新程序并输入 import pygame ,我得到了同样的错误。 I installed pygame with pip and are using python 3, version 3.6.8.我安装了 pygame 和 pip 并使用 python 3,版本 3.6.8。

I have tried reinstalling pygame and trying to install in with sudo.我尝试重新安装 pygame 并尝试使用 sudo 安装。 I also have tried using pip3, same result.我也尝试过使用 pip3,结果相同。

[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license()" for more information.
>>> import pygame
Traceback (most recent call last):
  File "<pyshell#0>", line 1, in <module>
    import pygame
ModuleNotFoundError: No module named 'pygame'
>>> 

If you have pip installed, inside the terminal you should be doing:如果您安装了 pip,在终端内您应该执行以下操作:

pip install pygame

Also, make sure you actually have pip installed.. https://www.makeuseof.com/tag/install-pip-for-python/ Hope that helps, if it works, please mark my question as the answer.另外,请确保您确实安装了pip Good luck with your py-games.祝你的 py 游戏好运。 Welcome to the community!欢迎来到社区!

Turns out I had to use 'pip3' and not just 'pip'.结果我不得不使用'pip3'而不仅仅是'pip'。 Thanks to everybody who helped.感谢所有帮助过的人。

Use pip3 pygame instead of pip pygame as on some systems with both python 2 and python 3, pip points to python 2's install, whereas pip3 points to python 3. Use pip3 pygame instead of pip pygame as on some systems with both python 2 and python 3, pip points to python 2's install, whereas pip3 points to python 3.

You can confirm this using您可以使用确认这一点

$ ls -l `which pip`
$ ls -l `which pip3`

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM