为Mac OS X 10.6.8安装Pygame。

[英]Installing Pygame for Mac OS X 10.6.8

Using Python 2.7.2. When I try to import pygame I get this error message:

使用Python 2.7.2。当我试图导入pygame时,我得到了这个错误信息:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  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

I'm not exactly sure what this means. Should I compile pygame myself?


5 个解决方案



The Python 2.7.3 .dmg Mac OS installer installs both 64-bit and 32-bit binaries in:

Python 2.7.3 .dmg Mac OS安装程序安装了64位和32位二进制文件:


/图书馆/框架/ Python.framework /版本/ 2.7 / bin /

There is a 32-bit binary called python2.7-32 in that folder.


To use it in the Terminal simply type $ python2.7-32 instead of python

要在终端中使用它,只需输入$ python2.7-32,而不是python。

To use it in IDLE simply rename the 64-bit python2.7 binary to something like python2.7-64 then rename python2.7-32' topython2.7` and next time you launch IDLE or the Terminal it will use the 32-bit binary. Change it back when you are done.

要在IDLE中使用它,只需将64位的python2.7二进制文件重命名为python2.7-64,然后重新命名python2.7-32' topython2.7 ',下次启动IDLE或终端时,它将使用32位二进制。当你做完的时候把它换回来。

You can also force launch IDLE in 32-bit mode from the Terminal:


$ arch -i386 /Library/Frameworks/Python.framework/Versions/2.7/bin/idle2.7 -n

$ arch -i386 /库/框架/Python.framework/版本/2.7/bin/idle2.7 -n。

You can create a shell script Automator application to make it easier to launch.




The clue is in the last line no matching architecture in universal wrapper. Most likely you are using precompiled 32-bit binaries on a 64-bit system.


You can try reinstalling or compiling from scratch but it would probably be far easier to just force python to run in 32-bit. Lots more info over here in this post.




I was having the same problem. I had Python 2.7.2, the installation version for OSX 10.6. Here is what I did to fix it:

我也有同样的问题。我有Python 2.7.2, osx10.6的安装版本。下面是我所做的修复工作:

1) Deleted my current installation of Python, both from the applications folder and from /Library/Frameworks/Python.framework (I just deleted 2.7.2, left 3.2 alone)


2) Reinstalled Python 2.7.2, the installation version for OSX 10.3 (my pygame installation file was labeled for OSX 10.3, which prompted me in this direction)

2)重新安装Python 2.7.2, osx10.3的安装版本(我的pygame安装文件被标记为osx10.3,提示我在这个方向)

3) Reinstalled pygame


Now pygame imports without throwing an error.




If you don't want to mess with system file then the easiest way is reinstalling Python 2.7.2 but the 32-bit version only. Get it here.

如果您不想破坏系统文件,那么最简单的方法是重新安装Python 2.7.2,但是只需要32位版本。把它在这里。

The dmg that includes both 64/32 bits is causing this mess.




What I'd recomend is using a decent Python IDE, like PyCharm.

我想要的是使用一个像样的Python IDE,比如PyCharm。

I've installed both the 3.3(x64), 3.3(x86) and the 2.7.6 from python.org with both architectures included.


All I have to do is to set up an interpreter configuration for each and I can pick and choose on a project by project level.


For me this is the definite way of smooth Python Development, contra Python Mangling and manual workarounds.


The Community Version of the PyCharm IDE is even free as in beer! Go get it over at JetBrains Site

社区版的PyCharm IDE甚至是免费的啤酒!到JetBrains网站去买。

It's a breeze to use and behaves the same across both Windows, Linux and OS X. It also acts as a package manager, so you can install different components straight from the IDE and run Console sessions using different configurations. It also lets you set up virtualenv's easily.

在Windows、Linux和OS x上使用和操作都是一样的,它也是一个包管理器,所以您可以直接从IDE安装不同的组件,并使用不同的配置运行控制台会话。它还可以轻松设置virtualenv。

Enough propaganda! Go try it out yourself instead.


And yes, I got PyGame working using this approach...





© 2014-2019 ITdaan.com 粤ICP备14056181号