Installing pygame on OS X with a Homebrew Python 2.7 install

Solved this surprisingly quickly today thanks in part to this post by Basti am. His post was mostly correct but some parts have changed, so I’m going to document how I got it working. Note that this method will miss out PNG, SCRAP, and PORTMIDI support. Good luck getting those working!

  1. Install Python via Homebrew:
    brew install python
  2. Install pip (because one package manager isn’t enough, right Python?):
    easy_install pip
  3. Install numpy with pip:
    pip install numpy
  4. Install the pre-requesites for pygame with Homebrew:
    brew install sdl sdl_ttf sdl_image sdl_mixer
  5. Download the pygame source. It’s one of the top links. Extract it somewhere and go to that directory in a terminal.
  6. Run python
  7. Fix the Setup file to point to your Homebrew SDL libraries, not OS X ones (which are missing stuff). Change the lines starting SDL, FONT, IMAGE, and MIXER to read:
    SDL = -I/usr/local/include/SDL -L/usr/local/lib -lSDL
    FONT = -lSDL_ttf
    IMAGE = -lSDL_image
    MIXER = -lSDL_mixer

    Below those definitions are lines commented out that enable/disable features. Remove the # to uncomment the ones you want.
  8. Run python install.
  9. Success!

Good luck!

This entry was posted in Blog, Noteworthy. Bookmark the permalink.
  • I want you kiss you for this.

  • Anonymous

    THANK YOU!  Getting anything python gaming related setup properly in OSX has been a royal pain.

  • following this I get a kCGErrorInvalidConnection: CGSGetCurrentCursorLocation: Invalid connection when trying to run pygame.display.set_mode

  • Thanks!

  • Anonymous

    Please note there’s a new, much easier solution now:

  • I love you bro!!! lol

  • Anonymous

    For step 5, I used `pip install -b pygame pygame` to download and unpack it into a new folder.

  • Thank you – your SDL flag was the final piece of the puzzle to get this working. It appears that brew install python now installs pip for you, so you won’t need to run ‘easy_install pip’.

  • stevematdavies where is that in the default python folder

  • Matt Jackson

    src/scale_mmx64.c:499:27: error: invalid instruction mnemonic ‘movsxl’

    asm __volatile__( ” /* MMX code for inner loop of X bilinear filter */ ”

    using ipython and python 2.7.3

  • Charlo

    when I open idle and type “import pygame” to test it I get this error. Traceback (most recent call last):
    File “”, line 1, in
    import pygame
    File “/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pygame/”, line 95, in
    from pygame.base import *
    ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pygame/, 2): no suitable image found. Did find:
    /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pygame/ no matching architecture in universal wrapper

    please help

  • Jiemmie Hean

    Worked like a charm. Can’t thank you enough.