Pygame on OS X Leopard
January 20, 2009
Skip to successful instructions
Tonight I wanted to start a new Pygame project to learn basic game development. I thought this would be rather easy, but apparently I’m not the only one who has had trouble.
Attempt 1 – Macports
Reading the Pygame download page I notice that it mentioned Macports. So I fired up Terminal, typed in sudo port install py-game and then waited about 5 mins for it to download and build everything.
Time to try it out.
geoffs-mac:~ geoff$ python
Python 2.5 (r25:51918, Sep 19 2006, 08:49:13)
[GCC 4.0.1 (Apple Computer, Inc. build 5341)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pygame
Traceback (most recent call last):
File "", line 1, in
ImportError: No module named pygame
Not cool. A little bit of searching and I found that for some reason Macports installed pygame under /opt/local/lib/python2.4/site-packages/pygame. This might be good if you use the Macports python but clearly not suitable for the default pre-installed Python 2.5.
As a last ditch effort to use the Macport Pygame I tried copying the /opt/local/lib/python2.4/site-packages/pygame into /Library/Python/2.5/site-packages which resulted in a whole heap of Python C API version mismatch warnings.
Oh well, rm -rf /Library/Python/2.5/site-packages/pygame
Attempt 2
Ok, time to try the pre-compiled installers.
I downloaded the OS X 10.5 installer from the Pygame downloads. However when I ran it, on the select destination screen it kept telling me that my startup volume was not acceptable as “System Python 2.5 is required”. Yet python was clearly running Python 2.5 (r25:51918, Sep 19 2006, 08:49:13)
I installed the Python package linked to on this page. I’m not sure what the package does that the default Python didn’t, but others were recommending it worked for me as well.
Then I ran the Pygame installer again and all was good. That is, until I tried importing pygame again.
geoffs-mac:~ geoff$ python
Python 2.5 (r25:51918, Sep 19 2006, 08:49:13)
[GCC 4.0.1 (Apple Computer, Inc. build 5341)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pygame
Traceback (most recent call last):
File "", line 1, in
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/pygame/__init__.py", line 37, in
_check_darwin()
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/pygame/__init__.py", line 34, in _check_darwin
raise ImportError("PyObjC 1.2 or later is required to use pygame on Mac OS X. http://pygame.org/wiki/PyObjC")
ImportError: PyObjC 1.2 or later is required to use pygame on Mac OS X. http://pygame.org/wiki/PyObjC
>>>
So back to the Pygame downloads page to grab pyobjc-1.4-py2.5-macosx10.4.mpkg.zip. Don’t be put of by the 10.4 in the filename – this is the one you want. The installer completed without troubles, and I could finally import pygame properly.
The Instructions
Without the waffle.
- Download and install python-2.5-macosx.dmg
- Download and install pyobjc-1.4-py2.5-macosx10.4.mpkg.zip
- Download and install pygame-1.8.1release-py2.5-macosx10.5.zip
- Test it in Terminal:
geoffs-mac:~ geoff$ python Python 2.5 (r25:51918, Sep 19 2006, 08:49:13) [GCC 4.0.1 (Apple Computer, Inc. build 5341)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import pygame >>>
What should have been five minutes, was more than 30 minutes of hassle. Now, time to start writing my game.
Entry Filed under: development. Tags: macports, osx, pygame, python.
1.
Cameron Hayne | February 2, 2009 at 7:34 am
I didn’t like the idea of installing things (python, pyobc) that already came with Leopard (in perfectly good versions) and so I followed (more or less) the instructions at http://pygame.org/wiki/MacCompile
to install what what necessary and compile pygame from source.
See details on my blog: http://franktheblue.blogspot.com/
2.
Tyler | February 8, 2009 at 6:38 pm
Brilliant. Thank you. I was looking for exactly this and it worked.
3.
Ddes | February 24, 2009 at 2:22 am
It doesn’t work for me. Tried installing via macports, tried your way. Both times it fails with “no module named pygame”. /me cries
4.
Cameron Hayne | February 24, 2009 at 3:20 am
@Ddes:
What do you have in /Library/Python/2.5/site-packages after the installation?
You should see a folder named “pygame-1.8.1release-py2.5-macosx-10.5-i386.egg” there.