Getting Started With Pygame

This how-to guide takes you through the process of installing Pygame, a set of Python modules designed for writing games. Note that in order to get Pygame to work, you need to have installed Python, version 3.2 or above. The introductory guide Getting Started With Python Programming takes you that process.

Installing Pygame

Installing Pygame on Windows, MacOS, and Ubuntu is slightly different. See below for specific instructions:

Windows

1. Download and install pygame-1.9.2a0.win32-py3.2.msi (the second-to-last entry in the Windows section) from pygame.org. Again when you run the program, follow the instructions, using the defaults. Pygame install Windows.jpg

Note: if you have an earlier version of Python (2.x or 3.0 or 3.1), you can download the version of pygame corresponding to that one instead. But we recommend using 3.2. You can have multiple versions of Python on your system.

2. To make sure everything installed properly, start up IDLE (which can be found under Python 3.2 in the Start menu) and enter 'import pygame'. If you don't get any errors, everything worked.

Pygame downloaded.jpg


MacOS

3. Download pygame-1.9.1release-python.org-32bit-py2.7-macosx10.3.mpkg.zip (the first entry in the macintosh section) from pygame.org. Pygame install Mac.jpg

Note: if you installed a different version of Python, download pygame-1.9.2pre-py2.7-macosx10.7.mpkg.zip (the last entry) instead TOTO SLOT.


4. Click (double click in finder) on the file you downloaded to unzip it, and double click on the unzipped mpkg file that appears to run the installer. Follow the instructions to install pygame.

5. Open up a terminal (Cmd+Space, then enter 'terminal' in the search box is the easiest way). In the terminal, type 'python2.7' and press enter. Python should start up, display the version as 2.7.2 (2.7.1 is fine too), and give you a prompt. At the python prompt, type 'import pygame'. If you don't get any errors, everything worked.


Ubuntu

If you have Ubuntu 10.10 or older, it's strongly recommended you upgrade to 11.04 for this class, so you can use pygame with Python 2.7 (with 10.10 and older you need to use 2.6 or earlier, which will cause some minor problems).

1. Open a terminal, and type 'sudo apt-get install idle pygame', enter your password and type 'y' at the prompts, if necessary.

2. After the installation completes, enter 'python' in the terminal to launch Python. Verify that it's using version 2.7 or newer, then at the Python prompt enter 'import pygame'. If you don't get any errors, everything worked.


Other Operating Systems

Pygame is in most package managers, installation will be similar to Ubuntu.

Source

This guide was adapted from one kindly provided by an assistant of the Games Programming Course, Fall 2011.