安装Pygame后pygame.init()显示为未定义变量
我正在尝试用Pygame写一个简单的Python应用程序:
import pygame, sys
from pygame.locals import *
pygame.init()
DISPLAYSURF = pygame.display.set_mode((400, 300))
pygame.display.set_caption('Hello world!')
while True: # main game loop
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
pygame.display.update()
但是,PyDev却抱怨说init()是一个未定义的变量,尽管它能识别Pygame库。我使用的是Python 2.7.6作为解释器。
这是错误信息的详细内容:
Traceback (most recent call last):
File "/Users/dannychia/Documents/workspace/PygameSample/PygameSample.py", line 6, in <module>
import pygame, sys
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pygame/__init__.py", line 95, in <module>
from pygame.base import *
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pygame/base.so, 2): no suitable image found. Did find:
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pygame/base.so: no matching architecture in universal wrapper
有没有人知道怎么解决这个问题?
1 个回答
2
这里有一些建议,可能会解决你的问题:
-我注意到你使用的是32位版本。考虑到你可能有一台64位的电脑,可能你安装的是64位的Python版本。这个错误有时是因为位数不匹配造成的。你可以这样检查你的Python版本的位数:
import platform
platform.architecture()
-根据这个问题,有时候卸载pygame,然后重新下载并安装它,可以解决这个问题。