Pygame on OS X Leopard

January 20, 2009 at 11:53 am

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.

Share this: Twitter

Facebook

Like this: Like Loading...

Entry filed under: development. Tags: macports, osx, pygame, python.