Making Games 2
Making Games 2
Making Games 2
CHAPTER 1 – INSTALLING
PYTHON AND PYGAME
What You Should Know Before You Begin
It might help if you know a bit about Python programming (or how to program in another
language besides Python) before you read through this book; however even if you haven’t you
can still read this book anyway. Programming isn’t nearly as hard as people think it is. If you ever
run into some trouble, you can read the free book ―Invent Your Own Computer Games with
Python‖ online at http://inventwithpython.com or look up a topic that you find confusing on the
Invent with Python wiki at http://inventwithpython.com/wiki.
You don’t need to know how to use the Pygame library before reading this book. The next
chapter is a brief tutorial on all of Pygame’s major features and functions.
Just in case you haven’t read the first book and already installed Python and Pygame on your
computer, the installation instructions are in this chapter. If you already have installed both of
these then you can skip this chapter.
The Python interpreter software can be downloaded from the official website of the Python
programming language, http://www.python.org. You might want the help of someone else to
download and install the Python software. The installation is a little different depending on if
your computer’s operating system is Windows, Mac OS X, or a Linux OS such as Ubuntu. You
can also find videos online of people installing the Python software on their computers at
http://invpy.com/installing.
Windows Instructions
When you get to http://python.org, you should see a list of links on the left (such as ―About‖,
―News‖, ―Documentation‖, ―Download‖, and so on). Click on the Download link to go to the
2 http://inventwithpython.com/pygame
download page, then look for the file called ―Python 3.2 Windows Installer (Windows binary --
does not include source)‖ and click on its link to download Python for Windows.
Double-click on the python-3.2.msi file that you've just downloaded to start the Python installer.
(If it doesn’t start, try right-clicking the file and choosing Install.) Once the installer starts up,
just keep clicking the Next button and just accept the choices in the installer as you go (no need
to make any changes). When the install is finished, click Finish.
Mac OS X Instructions
Mac OS X 10.5 comes with Python 2.5.1 pre-installed by Apple. Currently, Pygame only
supports Python 2 and not Python 3. However, the programs in this book work with both Python
2 and 3.
The Python website also has some additional information about using Python on a Mac at
http://docs.python.org/dev/using/mac.html.
You also need to install the IDLE software. From the terminal, type in ―sudo apt-get
install idle‖. The root password is also needed to install IDLE (ask the owner of your
computer to type in this password for you).
Starting Python
We will be using the IDLE software to type in our programs and run them. IDLE stands for
Interactive DeveLopment Environment. The development environment is software that makes it
easy to write Python programs, just like word processor software makes it easy to write books.
If your operating system is Windows XP, you should be able to run Python by clicking the Start
button, then selecting Programs, Python 3.1, IDLE (Python GUI). For Windows Vista or
Windows 7, just click the Windows button in the lower left corner, type ―IDLE‖ and select
―IDLE (Python GUI)‖.
If your operating system is Max OS X, start IDLE by opening the Finder window and click on
Applications, then click Python 3.2, then click the IDLE icon.
If your operating system is Ubuntu or Linux, start IDLE by opening a terminal window and then
type ―idle3‖ and press Enter. You may also be able to click on Applications at the top of the
screen, and then select Programming, then IDLE 3.
The window that appears when you first run IDLE is called the interactive shell. A shell is a
program that lets you type instructions into the computer. The Python shell lets you type Python
instructions, and the shell sends these instructions to the Python interpreter to perform.
Installing Pygame
Pygame does not come with Python. Like Python, Pygame is available for free. You will have to
download and install Pygame, which is as easy as downloading and installing the Python
interpreter. In a web browser, go to the URL http://pygame.org and click on the ―Downloads‖
link on the left side of the web site. This book assumes you have the Windows operating system,
but Pygame works the same for every operating system. You need to download the Pygame
installer for your operating system and the version of Python you have installed.
You do not want to download the ―source‖ for Pygame, but rather the Pygame ―binary‖ for your
operating system. For Windows, download the pygame-1.9.1.win32-py3.2.msi file. (This is
Pygame for Python 3.2 on Windows. If you installed a different version of Python (such as 2.7 or
2.6) download the .msi file for your version of Python.) The current version of Pygame at the
time this book was written is 1.9.1. If you see a newer version on the website, download and
install the newer Pygame.
For Mac OS X, download the .zip or .dmg file for the version of Python you have and run it.
For Linux, open a terminal and run ―sudo apt-get install python-pygame‖.
On Windows, double click on the downloaded file to install Pygame. To check that Pygame is
install correctly, type the following into the interactive shell: