Wednesday, February 29, 2012

Installing Pygame on Mac OS X Lion (10.7)

I managed to trick pygame into installing on Leopard some time ago. Now, I've had the challenge of installing pygame on OS X Lion.

On my first several tries to install pygame on Lion, I got various errors. It couldn't find any such thing as pygame, at first, then when I installed a 32/64 bit version of Python 2.7 (Pygame doesn't work with Python 3.X out of the box) I got the more encouraging error that, while it could find pygaame, it couldn't find a matching architecture in pygame for it to use.

I tried about 5 different combinations of install with no luck. Today I finally hit on a working combination of Python and Pygame. These were installed on new, up-to-date Mac Minis of the present generation (only run Lion.)


Install the Wrong Python

First, install the 32-bit only Python that says that it's for i386/PPC, OS X versions 10.3 to 10.6:
http://python.org/ftp/python/2.7.2/python-2.7.2-macosx10.3.dmg

Then, install the Pygame for Python 2.7 for OS X 10.3:
http://pygame.org/ftp/pygame-1.9.1release-python.org-32bit-py2.7-macosx10.3.dmg

You should now be able to start IDLE (for the version of Python above) and enter "import pygame" at the prompt without getting any complaints in return.

Celebrate with a Hat

Now make yourself a hat that says "Lion Tamer" and celebrate.

Notes:
It appears to be possible to use pygame with Python 3, if you install the files in the right locations yourself--no easy install package here. You'll still need the 32 bit only version of Python if you use the precompiled binary files for pygame, above.

Compiling pygame for your system should solve the problem with the architecture mismatch error. But I didn't feel like opening that particular can of worms: installing Mac devtools on one of the 12 systems I'm installing on in our school's lab, not my personal system, hoping it would compile cleanly, then having to set up and test it with the installed version of Python. Etc.

I'm saving my feelings on this for my other blog that's Python-specific.

3 comments:

  1. I installed pygame on OSX Lion and it works fine except when i try to load images..
    .bif=pygame.image.load("bg.jpeg")
    error: File is not a Windows BMP file

    Have you had this error? did you find a solution?

    ReplyDelete
  2. Sorry, I haven't had that problem. It looks like it's expecting a BMP file even though you're loading a jpg. I haven't used that function--is there something that would allow you to let it know you're using a jpg and not a BMP?

    ReplyDelete
  3. I was using pygame-1.9.2pre-py2.7-macosx10.7 and anything I tried resulted in the same outcome "File is not a Windows BMP file".

    After reading your post I decided to install the Pygame for Python 2.7 for OS X 10.3 as you suggested, and this worked perfect, loads all the images :) Thanks a million I was just about to give up on it!

    ReplyDelete