Python iconBefore the tutorial, I want to point out a few of the best authors of “beginning python” books. The first is Al Sweigart, who not only sells his book in print on Amazon, but also offers them for free on his website. His three beginning python books, Invent You Own Computer Games with Python, Making Games with Python & Pygame, and Hacking Secret Ciphers with Python can be found for free in PDF here. If you want to purchase the print versions, go here. Another author is Jason Briggs, whose book Python for Kids can be found here. The last author in our spotlight, Professor Craven, has an incredible website called Program Arcade Games with Python and his book on the same subject can be found here. All of these books are written for Python 3 programming.

You can find a great writeup about Pycharm 3 CE, the best free IDE you can get for Python here.

Now about the tutorial. All of the credit for this goes to Julian at albrecht.cn. He did all of the heavy lifting. I just corrected a few things and cleaned it up a little. Please note, there are two command line entries that I had to break into two lines because I like my ridiculously narrow blog. I noted them in the tutorial and reminded you to enter them on one line. Here we go:

Install the Xcode Command Line Tools from Apple or from here.

Install Quartz from here

Install Homebrew and necessary tools:

ruby -e “$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)”

brew update

brew install python3 (this currently installs version 3.3.3)

brew install mercurial

brew install sdl sdl_image sdl_mixer sdl_ttf portmidi

brew install –HEAD smpeg

*** If you get an error here then type this on one line ***

brew install –HEAD

https://raw.github.com/Homebrew/homebrew-headonly/master/smpeg.rb

Make sure you are using TWO ‘-’ (dashes) in front of HEAD.

Install pip:

/usr/local/Cellar/python3/3.3.3/bin/easy_install3 pip

Clone the pygame repository:

cd /Users/YourName/Downloads
hg clone https://bitbucket.org/pygame/pygame
cd pygame
cd src

Copy this file into src, replacing the one there.

Now install pygame by typing this on one line:

/usr/local/Cellar/python3/3.3.3/bin/pip3
install /Users/YourName/Downloads/pygame

That’s it. If this tutorial helped you, please follow me on twitter @dudeslife .

33 Responses to “Install Python 3.3.3 + Pygame on Mac OS X Mavericks”
  1. maze666 says:

    Thanks a lot for your step-by-step tutorial. It is the first one I have found that works without any issue.
    Maybe you can add the following for testing the installation:

    python3
    >>> import pygame
    >>> pygame.init()
    (6, 0)
    >>> pygame.display.set_mode((800, 600))

    >>> raise SystemExit

    After pygame.init the pygame snake icon appears in your dock.
    After issuing pygame.display.set_mode a Window should appear on the screen.

  2. Jon says:

    HI the tutorial is great but I got unfortunately some trubles. It’s maybe because of my english, but In this line : “copy this file into src, replacing the one there” I don’t understand which is “the one there” and what i have to do.
    thanks in advance and I hope I don’t install this stuff for nothing because of my inefficiency.

    • @dudeslife says:

      the word ‘file’ is a link. here is the url:

      http://dudeslife.com/images/scale_mmx64.c

      you save that file to your desktop and copy it into the dir called src wherever you cloned the pygame directory. It will replace the file scale_mmx64.c that is already there. hope this clears it up for you.

      • Jon says:

        thank you for your fast answer.
        I still have a problem. When i type “import pygame” in python, i have : “ImportError: No module named ‘pygame’”. Obviously, I failed and I don’t know what to do. Maybe the problem comes from the last lignes “/usr/local/Cellar/python3/3.3.3/bin/pip3
        install /Users/YourName/Downloads/pygame” because of my first try where the directory was not the good one. How can i uninstall pygame in order to reinstall it ?

        • @dudeslife says:

          if it did not install, then you don’t need to remove anything. make sure when you enter that line that you substitute the ‘YourName’ with your actual user name.

          if it seemed to install ok when you followed the steps, you may be trying to use a different version of python that was already on your mac. make sure you are using the newly installed python 3.3.3.. edit your .bash_profile adding this line:

          alias python=’/usr/local/Cellar/python3/3.3.3/Frameworks/Python.framework/Versions/3.3/bin/python3′

          if you follow the steps of the tutorial exactly it will work. I have tried it on multiple machines and other users have commented that it works. good luck.

  3. Jon says:

    When i try to install pygame, it’s written that “Framework SDL not found…Framework SDL_ttf not found…SDL_image not found…no previously-included directories found matching ‘*/CVS’…no previously-included directories found matching ‘*/*/CVS …” like if the line “brew install sdl sdl_image sdl_mixer sdl_ttf portmidi” hasn’t worked. But I already typed it and it’s worked.
    Of course I substituted YourName by my user name and I used Python 3.3.3.
    My mistake must be that I didn’t install the Xcode Command Line Tools at the beginning, thinking that owning the Xcode application was enough. So I admit it, I didn’t follow the tutorial exactly in the right order. But when I try to rewrite the commands, everything is already installed according to the terminal. Does it exist a way to restart from the beginning ?

    • @dudeslife says:

      did you use brew doctor to make sure there were no problems after you installed homebrew? As far as it being installed and not working or removing it other than doing it manually, I have no idea. Sorry. Good Luck.

  4. James says:

    How would this process change for Python 3.2.2 and Lion?

  5. duder says:

    Thanks this worked! I just had to replace 3.3.3 with 3.3.4 at 2 places. I’m really glad I found this!

  6. Sean says:

    When I try to enter “brew install –HEAD smpeg” or “brew install –HEAD https://raw.github.com/Homebrew/homebrew-headonly/master/smpeg.rb” I get an error that says
    Error: No available formula for –head
    Searching taps…

    Any ideas? I ran brew doctor and got two warnings:
    “config” scripts exist outside your system or Homebrew directories
    Unbrewed dylibs were found in /usr/local/lib.

  7. iamtheguy says:

    I have the same problem as Sean when I enter “brew install -HEAD smpeg” or “brew install -HEAD https://raw.github.com/Homebrew/homebrew-headonly/master/smpeg.rb” (Error: No available formula for -head). When I run brew doctor I get:

    Warning: /usr/bin occurs before /usr/local/bin
    This means that system-provided programs will be used instead of those
    provided by Homebrew.

    Is this warning related at all?

    • Sean says:

      I was getting that warning so I did as brew doctor suggested and changed up the path. I was able to get around the previous error by using two dashes before HEAD instead of one, and I made it through the rest of the instructions. Thanks a bunch for them! Previously I was using the system’s python, but now that I’ve changed the path, do I need to do anything to make sure that the version I just downloaded is used instead? Also, the pygame folder is still in my Downloads folder. Can I move it anywhere in my computer and it will still work?

      • @dudeslife says:

        you can edit your bash profile to alias the word python to the proper one or if you use pycharm, you can set it to whatever python you want.. the pygame dir in your downloads can be deleted. it was just used to build/install the lib. enjoy!

  8. Nico says:

    I am quite new to python and I tried to follow all of the steps. I still experience an issue when trying to check whether pygame is installed or not.

    The first command
    >>>import pygame
    seems to be recognized, but when I input the second command. This is what happens

    >>> import pygame
    >>> pygame.init()
    Traceback (most recent call last):
    File “”, line 1, in
    AttributeError: ‘module’ object has no attribute ‘init’
    >>>

    Do any of you have a solution for this?

  9. Eugene says:

    Would you know how to get png or jpeg support for pygame?

  10. Mark says:

    Hey. I’ve been trying for days to get pygame to work.

    Everything in this tutorial has worked for me until installing pip, it says no such directory exists.

    Any help?
    Thanks a lot

  11. Max says:

    I don’t understand how to install pip. Running /usr/local/Cellar/python3/3.3.3/bin/easy_install3 pip by itself doesn’t do anything, and I don’t know what else to do. I’ve run into a bunch of different tutorials online for installing pip but they are confusing and seem to differ from each other. Any advice?

  12. fid says:

    Thanks for the tutorial DudesLife.

    I had a little trouble when following this tutorial. I already had python 2.7 and 3.4 installed on my system. I ended up getting some warnings. Is there a way I can revert all, or some, of the changes and start over? I also had a problem when running pip. It existed in a different directory because of having python already installed, I guess.
    “Warning: Python is installed at /Library/Frameworks/Python.framework

    Homebrew only supports building against the System-provided Python or a
    brewed Python. In particular, Pythons installed to /Library can interfere
    with other software installs.

    Warning: /usr/bin occurs before /usr/local/bin
    This means that system-provided programs will be used instead of those
    provided by Homebrew. The following tools exist at both paths:

    2to3
    2to3-2.7
    idle
    idle2.7
    pydoc
    pydoc2.7
    python
    python-config
    python2.7
    python2.7-config
    pythonw
    pythonw2.7
    smtpd.py
    smtpd2.7.py

    Consider setting your PATH so that /usr/local/bin
    occurs before /usr/bin. Here is a one-liner:
    echo export PATH=’/usr/local/bin:$PATH’ >> ~/.bash_profile”
    And
    “.app bundles were installed.
    Run `brew linkapps` to symlink these to /Applications.
    Error: The `brew link` step did not complete successfully
    The formula built, but is not symlinked into /usr/local
    You can try again using:
    brew link python3″
    And
    “checking for headers required to compile python extensions… ./configure: line 14647: /Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/python-config: No such file or directory
    not found
    configure: error: Python headers not found”

    Does it sound like I am going to have trouble?
    fid

  13. Mark says:

    I’m having problems with the pip. When I put in that code you have, here is the outcome:

    src tokyomark$ /usr/local/Cellar/python3/3.3.3/bin/easy_install3 pip
    -bash: /usr/local/Cellar/python3/3.3.3/bin/easy_install3: No such file or directory

  14. Aaron says:

    Hey, I’ve been trying for the past few weeks to get python and pygame working on my mac. I’m actually incredibly frustrated and I was hoping someone might be able to help me. So, I’ve completed all of the steps. I have the pygame folder in my downloads and I replaced the src and everything. I’m using 3.4 and I was able to instal everything correctly by changing what I needed to. It worked fine. However, I can’t figure out if I’m an idiot and missed something or what, but after doing the steps, when I try to run IDLE and import pygame it still says the module isn’t there.

    I’ve tried screwing around with the frameworks and everything. I got close when I placed the pygame folder into a folder within the frameworks but I don’t think it was correct. It would import pygame, but pygame didn’t have any function or modules at all. pygame.display… “display” was not found. So, it was reading pygame, but not display which should’ve been readable. I took everything that I had messed with out and I’m still at the last step.

    I have completed everything, but it’s still not working for me. What “Python” or IDLE or whatever do I need to use in order for it to find the pygame folder. Right now it’s just sitting in the dowloads and I don’t think that that’d do anything for me. where do I put it or what do I do with it because having it just sit there does nothing. I couldn’t even use it in terminal. I’m just really getting upset and desperate. I just want to code without having to be at the school. ;(

    • @dudeslife says:

      You need to dig down into the directory of the python you just installed to find the correct idle. with my tutorial, you will find idle.app in /usr/local/cellar/python3/3.3/

  15. Trevor says:

    This command can also resolve smpeg install problems: brew tap homebrew/headonly

  16. Giova says:

    Hi guy,
    i’ve a problem, i can’t install “/usr/local/Cellar/python3/3.3.3/bin/easy_install3 pip”, “No such file or directory”.
    All the other step are perfect, all installed.. but not the pip.
    I missed anything or there’s another way? (OSX Mavericks 10.9.3).
    thanks

    • Marcel says:

      Hi Giova,

      I installed it today on 10.9.3 and it works.
      What you have to do, is to use the correct Pyhton version number and name of the file, respectively, in that line of code. I checked the folder /usr/local/Cellar/python3/ and saw that it was ’3.4.1′ in my case and then I checked further and saw that the name of the file was ‘easy_install-3.4′.
      So, your line should probably look like this:

      /usr/local/Cellar/python3/3.4.1/bin/easy_install-3.4 pip

      Later on in the tutorial (last step), when you install pygame, you also need to replace the ’3.3.3′ with ’3.4.1′
      I hope that works for you.

      P.S. If you had installed Python and/or pygame before, you may have a bad app ‘IDLE’ in your applications folder or so. Do not use that one! Use the one that was installed with this tutorial, in my case it was in /usr/local/Cellar/python3/3.4.1/IDLE 3 – @dudeslife, sorry for the repetition.

  17.  
Leave a Reply