Installing pygame on my Mac

I have a MacBook Air running Mountain Lion (10.9). I also have a RaspberryPi that I want to use as a digital picture frame (along with a monitor – of course).

My choice of digital picture frame software is – home brew pygame – running from the console on the RaspberryPi.

On the RPi I get pygame with a rasbian image. On the Mac I have to install it by myself. I found a fine guide on pygame.org. Here is what I did:

  1. Installed python – the pure 32-bit 2.7.x from vpython.org
  2. Install VPython-Mac-Py2.7-x from vpython.org (which should include numpy)
  3. Installed the SDL libraries from libsdl.org. You will need base, SDL_mixer, SDL_ttf, and SDL_image.
  4. Installed the libjpeg and libpng libraries precompiled from ethan.tira-thompson.com
  5. Installed Xcode from Apple apps.
  6. Added command line tools. To do this start Xcode and go to Preferences under Xcode menu. Choose the Download tab and select Components and install.
  7. Installed XQuartz as Mountain Lion OS X no longer includes the X11 window system library. Find it on  xquartz.macosforge.org
  8. Downloaded pygame tar file from http://pygame.org/download.shtml Decompressed and extracted to create directory pygame1.9.1release
  9. Before compilation of pygame:
    1. SDL_x header files refer to SDL as <SDL/SDL_yy.h> However, a SDL directory is not under the include directory of SDL (SDL/Headers). To fix this in a simple way: I Went to directory /Library/Frameworks/SDL.framework/Headers
    2. then made a link as follows: ln -s SDL ./
  10. Changed to the pygame directory (normally pygame1.9.1release). Then switched to the super user. However, you can use the sudo command instead. I set the following compilation flags
    export CC='/usr/bin/gcc'
    export CFLAGS='-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk -I/opt/X11/include -arch i386'
     export LDFLAGS='-arch i386'
     export ARCHFLAGS='-arch i386'

    You must specify using the original location of X11. The mac does not have a ld.so.conf
    and apparently the links generated by XQuartz in /usr do not work correctly.

  11. Now execute:
    python config.py
    This should find the SDL, jpeg, png, and numpy librariespython setup.py build
    This will build in the directory before installing. It should complete with no errors. then python setup.py install
  12. Confirmed that it worked:Out of super user mode and in a terminal shellpython
    and within python import pygamethis gave no error and a simple pygame program ran fine.

Leave a Reply

Your email address will not be published. Required fields are marked *

  • Facebook
  • Google+
  • LinkedIn