3 Installation and Setup

INSTALLATION

To start writing code with Python and Pygame, it’s necessary to install several pieces of software. First is the Python interpreter itself, then we add the Pygame library, and finally we want a decent editor that makes writing the code easier. In this tutorial I’ll be using a lightweight IDE called Geany, but you’re free to choose whichever editor you prefer.

The way to install and setup each of these applications varies depending on which operating system you use, so choose the relevant section below according to your OS.

LINUX

Most Linux distributions come with Python already installed, but if it isn’t then you can search the software center or package manager (depending on your distro) in order to install it. This method can also be used to install Geany.

To get the Pygame library – after Python is installed you can type this command into a terminal:

python -m pip install -U pygame –user

To check if it has worked type in this line and it should start an example game (press the escape key to exit.)

python -m pygame.examples.aliens

WINDOWS

Note: We’ll be using the latest version of Python and it no longer supports Windows XP or earlier.

Visit the Python web page at www.python.org and click on Downloads/Windows for the latest Python 3 release. Download the file and execute it, to begin the installation. When the installer first starts there’s a checkbox option to Add Python to the path be sure to tick this or else it won’t work properly with the Geany editor (if you forget to do this, there’s a way to add the path manually which I’ll explain below. However it’s quite technical and convoluted so it’s quicker and easier to just reinstall Python and make sure that this checkbox is ticked.)

For the path variable to take effect it’s necessary to restart Windows. After the reboot you should now able to install Pygame, by typing the following line into a command prompt (or press the Windows key and R) :

python -m pip install -U pygame –user

To check if it worked type in this line and it should start an example game (press the escape key to exit.)

python -m pygame.examples.aliens

To install the Geany editor, visit the homepage at www.geany.org and look for the Windows binaries in the download section.

MANUALLY ADDING PYTHON TO THE PATH VARIABLE ON WINDOWS 10

This step is necessary in order for Python to work with the editor. The easiest way to do it is by simply ticking the checkbox when you run the Python installer, but if you didn’t do this, then adding Python to the path variable can be done manually by following the instructions below.

Before you start, you’ll need to know the location of the folder in which Python is installed.

Press the Windows key and type in Control Panel, then open this up. In the Control Panel, select View by: Large Icons, then click on System. In the window that opens, click the Advanced System Settings link, and then click the Environment Variables button. This will open a new window, click on the New button and type in the full path of the folder in which Python is installed. You’ll need to restart the computer for this setting to take effect.

<– back to contents