Daniel 'MaTachi' Jonsson

How to Install Pygame to Python 3 on Ubuntu

Installation

Start by installing all necessary dependencies, and mercurial and checkinstall for the installation:

sudo apt-get install python3-dev libsdl-image1.2-dev libsdl-mixer1.2-dev libsdl-ttf2.0-dev libsdl1.2-dev libsmpeg-dev python-numpy libportmidi-dev ffmpeg libswscale-dev libavformat-dev libavcodec-dev checkinstall mercurial

Then download the latest version of the Pygame source code with the following command (this uses mercurial):

hg clone https://bitbucket.org/pygame/pygame

Go into the downloaded Pygame directory:

cd pygame

Compile the source code by typing this command into the terminal:

python3 setup.py build

Finally install Pygame by doing this:

sudo checkinstall python3 setup.py install

Extra stuff

Click here to read why you should use checkinstall.

Use this command to see information about your pygame installation:

apt-get cache show pygame

And this command to uninstall Pygame:

dpkg -r pygame

or:

sudo apt-get remove pygame

Notes

The most recent stable pygame version when writing this is 1.9.1 (which is from August 2009). I did this installation on Ubuntu 12.04 and this was needed since there isn’t a python3-pygame available in the repository.

  • Carson

    I got these instructions from the pygame website once and they used to work. But i reinstalled my system some time ago and now I can’t even import pygame from python3 without getting errors after fallowing all the same steps again.

  • Carson

    This is what I get now.

    >>> import pygame
    Traceback (most recent call last):
    File “”, line 1, in
    File “/usr/local/lib/python3.2/dist-packages/pygame/__init__.py”, line 106, in
    import pygame.color
    File “/usr/local/lib/python3.2/dist-packages/pygame/colordict.py”, line 679
    u’gray17′ : (43, 43, 43, 255) ,
    ^
    SyntaxError: invalid syntax
    >>>

  • Simon

    This worked for me on Ubuntu 12.04 with Python3.2.3.
    Cheers!

  • http://twitter.com/feimamura Felipe Imamura

    Thanks, worked in Ubuntu 12.04

  • odin49

    Thank you, did copy paste using every step you indicate and it worked. You saved my day!

    • http://danielj.se MaTachi

      Great!

  • Erik

    Been trying on-and-off for about a month to get pygame installed on my laptop. This is the first set of instructions that worked. Thanks!

  • http://twitter.com/jetlund Ola Jetlund

    Thank you! After ten thousand different recipes from Google. This is the only one that works.

  • ksd

    How to install python3 in Ubuntu 12.04? From the software center there is a “Idle(for python 3)” software. Do I need to install that one first before installing pygame?