Python 2.7.3 installed on Mac OS X 10.7.5 and 10.8.2 (in two separate machines). When pygame v1.9.1 release (http://www.pygame.org/download.shtml) was installed, IDLE  or pyCharm keep giving the following annoying error.
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

There are some rather complicated solutions. But I eventually found out that it is a rather simple solution. Basically the problem is python 2.7.3 contains and installs both 64-bit and 32-bit binaries, and the default binary is 64-bit in the newer OS X versions (10.6 and up). Pygame is only compatible to 32-bit Python hence the error message.

To solve the problem, go to where the Python framework is installed, which can be found at
/Library/Frameworks/Python.framework/Versions/2.7/bin/

There are two files (NOT the shortcuts), one called python2.7-32 and the other is python2.7. Change the name python2.7 to python2.7-64 (this is the 64-bit file), and then rename python2.7-32 to python2.7.

Now the error is gone.

If you wish to run IDLE in 32-bit as well, you can run this comment from the Terminal:$ arch -i386 /Library/Frameworks/Python.framework/Versions/2.7/bin/idle2.7 -n

This is just optional.

To get pygame to work on OSX 10.6-10.8, you do not need to homebrew a separate pygame installation file. You certainly do NOT need to follow the Mountain Lion install instructions as detailed in here.

About these ads