无法导入pygame

问题描述 投票:0回答:1

在IDLE Python 3.7.2中运行导入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在Idle python 3.7.2中工作?

python import module pygame python-idle
1个回答
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
>>> 
© www.soinside.com 2019 - 2024. All rights reserved.