问题描述
我正在尝试使用 Pygame 编写示例 Python 应用程序:
I'm trying to write a sample Python application using Pygame:
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 作为解释器.
However, PyDev complains that init() is an undefined variable even though it recognizes the Pygame library. I'm using Python 2.7.6 as the interpretor.
这是堆栈跟踪:
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
有人有解决方案吗?
推荐答案
这里有一些建议.其中之一应该可以解决问题:
Here are some suggestions. One of these should solve the problem:
-我看到您的版本是 32 位版本.考虑到您可能拥有一台 64 位计算机,您可能拥有 64 位 Python 发行版.此错误有时是由比特率差异引起的.您可以像这样检查 python 发行版的比特率:
-I see that your release is the 32 bit version. Considering you probably have a 64 bit computer, it is possible that you have a 64 bit python distribution. This error is sometimes caused by bit rate differences. You can check the bit rate of the python distribution like so:
import platform
platform.architecture()
-根据这个问题,卸载pygame,重新下载并安装它似乎有时可以解决问题.
-According to this question, uninstalling pygame, and redownloading and installing it seems to fix the problem sometimes.
这篇关于pygame.init() 在安装 Pygame 后显示为未定义的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!