我正在尝试使用 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() 是一个 undefined variable ,即使它识别 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
谁有解决办法?
请您参考如下方法:
这里有一些建议。其中之一应该可以解决问题:
-我看到您的版本是 32 位版本。考虑到您可能有一台 64 位计算机,您可能有一个 64 位 python 发行版。此错误有时是由比特率差异引起的。您可以像这样检查 python 发行版的比特率:
import platform
platform.architecture()
-根据this问题,卸载 pygame,然后重新下载和安装它有时似乎可以解决问题。
