导入pygame时遇到问题

时间:2019-03-02 15:13:20

标签: python import module pygame python-idle

在IDLE Python 3.7.2中运行import pygame之后,现在已经在Anaconda spyder中尝试过并得到完全相同的错误

   import pygame: Traceback (most recent call last):
   File "<pyshell#1>", line 1, in <module>
    import pygame
   ModuleNotFoundError: No module named 'pygame'

在终端中,当我运行pip3时,请安装pygame:

  pip3 install pygame
   Requirement already satisfied:
   pygame in /usr/local/lib/python3.7/site-packages (1.9.4)

在IDLE Python 3.7.2中运行sys.path之后

['', '/Users/myname/Documents', '/Library/Frameworks/Python.framework/Versions/3.7/lib/python37.zip', '/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7', '/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/lib-dynload', '/Users/myname/Library/Python/3.7/lib/python/site-packages', '/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages']

所以我猜想系统上安装了多个版本的python,而pygame在3.7 / site-packages中。

如何使pygame在空闲python 3.7.2中工作?

1 个答案:

答案 0 :(得分:1)

现在解决:

>>> import sys
>>> sys.path.append('/usr/local/lib/python3.7/site-packages')
>>> import pygame
pygame 1.9.4
Hello from the pygame community. https://www.pygame.org/contribute.html
>>>