We will install Python, Pygame, and other software we will need.
Before we install Pygame, we need to have Python installed. On some operating systems Python is already installed. Pygame should be compatible with all Python versions. We will also need the NumPy numerical library. I am the author of two books published by Packt Publishing about NumPy – NumPy Beginner's Guide and NumPy Cookbook. Please refer to these books for more info about NumPy.
Installing on Debian and Ubuntu
Python might be already installed on Debian and Ubuntu, but the development headers are usually not. On Debian and Ubuntu, install python and python-dev with these commands:
sudo apt-get install python sudo apt-get install python-dev
Pygame can be found in the Debian archives http://packages.qa.debian.org/p/pygame.html. We can install NumPy with the following command:
sudo apt-get install python-numpy
Installing on Windows
The Windows Python installer can be found on www.python.org/download. On this website we can also find installers for Mac OS X and source tarballs for Linux, Unix, and Mac OS X.
From the Pygame website (http://www.pygame.org/download.shtml), we can download the appropriate binary installer for the Python version we are using.
Download a NumPy installer for Windows from the SourceForge website (http://sourceforge.net/projects/numpy/files/).
Installing Python on the Mac
Python comes preinstalled on Mac OS X. We can also get Python via MacPorts, Fink, or similar projects. We can install for instance the Python 2.6 port by running the following command:
sudo port install python26
Binary Pygame packages for Mac OS X 10.3 and up can be found on http://www.pygame.org/download.shtml. We can get a NumPy installer from the SourceForge website (http://sourceforge.net/projects/numpy/files/). Download the appropriate
.DMG
file. Usually the latest one is the best.Installing from source
Pygame is using the
distutils
system for compiling and installing. To start installing Pygame with the default options, simply run the following command:python setup.py
If you need more information about the available options, type the following command:
python setup.py help
In order to compile the code, you need to have a compiler for your operating system. Setting this up is beyond the scope of this book. More information about compiling Pygame on Windows can be found on http://pygame.org/wiki/CompileWindows. More information about compiling Pygame on Mac OS X can be found at http://pygame.org/wiki/MacCompile.