Skip to main content

CompileUbuntu — wiki

Install the development libraries and dependencies needed to install pygame.

Download pygame from bitbucket, build, then install!

Note: When building for both Python2 and Python3, do this from completely different download (build) directories)!

For rebuilding with the instructions below for a newer version upstream, use the commands hg pull and hg update to upgrade the download.

Python 2.x

#install dependencies
sudo apt-get install mercurial python-dev python-numpy python-opengl \
    libav-tools libsdl-image1.2-dev libsdl-mixer1.2-dev libsdl-ttf2.0-dev libsmpeg-dev \
    libsdl1.2-dev libportmidi-dev libswscale-dev libavformat-dev libavcodec-dev \
    libtiff5-dev libx11-6 libx11-dev fluid-soundfont-gm timgm6mb-soundfont \
    xfonts-base xfonts-100dpi xfonts-75dpi xfonts-cyrillic fontconfig fonts-freefont-ttf

# Grab source
hg clone https://bitbucket.org/pygame/pygame

# Finally build and install
cd pygame
python setup.py build
sudo python setup.py install

# Run some tests
python -m pygame.tests
python -m pygame.examples/aacircle
python -m pygame.examples/aliens
python -m pygame.examples/freetype_misc
python -m pygame.examples/glcube
python -m pygame.examples/sound
python -m pygame.examples/stars

Python 3.x

#install dependencies
sudo apt-get install mercurial python3-dev python3-setuptools python3-numpy python3-opengl \
    libav-tools libsdl-image1.2-dev libsdl-mixer1.2-dev libsdl-ttf2.0-dev libsmpeg-dev \
    libsdl1.2-dev libportmidi-dev libswscale-dev libavformat-dev libavcodec-dev \
    libtiff5-dev libx11-6 libx11-dev fluid-soundfont-gm timgm6mb-soundfont \
    xfonts-base xfonts-100dpi xfonts-75dpi xfonts-cyrillic fontconfig fonts-freefont-ttf

# Grab source
hg clone https://bitbucket.org/pygame/pygame

# Finally build and install
cd pygame
python3 setup.py build
sudo python3 setup.py install

# Run some tests
python3 -m pygame.tests
python3 -m pygame.examples/aacircle
python3 -m pygame.examples/aliens
python3 -m pygame.examples/freetype_misc
python3 -m pygame.examples/glcube
python3 -m pygame.examples/sound
python3 -m pygame.examples/stars

Python 3.x into virtual environment

To install pygame into a virtual environment it is recommended to first install and configure virtualenvwrapper.

# Install dependencies
sudo apt-get install mercurial python3-dev python3-numpy libav-tools \
    libsdl-image1.2-dev libsdl-mixer1.2-dev libsdl-ttf2.0-dev libsmpeg-dev \
    libsdl1.2-dev  libportmidi-dev libswscale-dev libavformat-dev libavcodec-dev

# Grab source
hg clone https://bitbucket.org/pygame/pygame

# Build pygame
cd pygame
python3 setup.py build

# Create and activate the virtual environment
mkvirtualenv NAME_OF_PROJECT --python=/usr/bin/python3
workon NAME_OF_PROJECT

# Install into the virtual environment
python3 setup.py install --prefix="$HOME/.virtualenvs/NAME_OF_PROJECT"

Installing pygame with pip

For this to work you must first follow the instructions to install the development dependencies for the version of python you're targeting as pip will download the source for pygame from bitbucket and compile it.

As an added bonus, if you add pygame to your requirements.txt and you also setup a virtual environment, pip will automatically install pygame into the virtual environment for you.

# System-wide installation WARNING: This is not advised! Don't do this if you don't know what you're doing!
sudo pip install hg+http://bitbucket.org/pygame/pygame


# Using a virtual environment. This is the recommended approach.
mkvirtualenv NAME_OF_PROJECT
cd /path/to/project/root
echo hg+http://bitbucket.org/pygame/pygame >> requirements.txt
pip install -r requirements.txt

Tests and examples with OpenGL

There is a bug in python3-opengl-3.0.2-1 in Ubuntu Xenial, this can be circumvented by installing https://launchpad.net/ubuntu/yakkety/amd64/python3-opengl/3.1.0+dfsg-1 from Yakkety. Download the package http://launchpadlibrarian.net/260965664/python3-opengl_3.1.0+dfsg-1_all.deb or a more recent version and install with sudo dpkg -i python3-opengl_3.1*.deb

.

Tests and examples without OpenGL

Building is not concerned with the availability of the package python-opengl or python3-opengl. Running the tests or running the example glcube however does need one of these packages. When OpenGL is not applicable, the test can be run in such a way to skip the OpenGL tests:

SDL_VIDEODRIVER=dummy SDL_AUDIODRIVER=disk python -m pygame.tests --exclude opengl
#or
SDL_VIDEODRIVER=dummy SDL_AUDIODRIVER=disk python3 -m pygame.tests --exclude opengl

Raspbian

For the time being, this is parked here but needs to find a place to a wiki page called CompileDebian which doesn't exist. The above also applies for Raspbian with the exception that instead of timgm6mb-soundfont the package musescore-soundfont-gm needs to be installed.