The prerequisites of Python
Before you get started, you need the following basic materials:
- A computer that can run Windows 7 or higher, Mac OS X 10.6 or higher, or Ubuntu 12.4 or higher. You may also use a Raspberry Pi as it comes preinstalled with Python, pygame, and the other software needed to complete the projects in this book.
- An Internet connection is necessary as some of the software you need to install on your computer might not be installed already. For example, Windows operating systems do not come with Python preinstalled, so an Internet connection will be needed; pygame is also not preinstalled on Windows, Mac, or Linux systems.
- Along with an Internet connection, you will also need a web browser, such as Firefox, Safari, Chrome, or Internet Explorer, which will allow you to visit the Python documentation pages.
Note
All of the code samples in this book are available for download on the Packt Publishing website.
Setting up your computer
There are many different computer operating systems, but the most common operating systems are Macintosh (Mac), Windows, and Linux. You should follow the installation steps that go with your operating system. There are some subtle but important differences between the systems.
For the projects in this book, we will be using Python 2.7. While there are higher versions than this (3.x), these versions do not work dependably with pygame on Windows, Mac, or Ubuntu Linux as yet. However, this book will be written to use conventions that work in both versions of Python so that projects are easily completed on Raspberry Pi (which uses Python 3.x that's been specially configured with pygame) with just a few modifications. These modifications will be duly noted.
For Mac and Ubuntu Linux users
Mac and Linux systems share enough similarities that people who use either Mac or Linux can follow the same set of instructions. These instructions will make note of any differences between Mac and Ubuntu Linux.
Python 2.7
At the time of writing, Mac OS X El Capitan comes with Python 2.7 preinstalled, so nothing extra needs to be done at this point.
Ubuntu Linux 15.10 has Python 2.7.10 installed by default, so users of this latest (as of writing this) version of Linux also need to do nothing extra at this point.
Terminal – the command line and the Python shell
Mac and Ubuntu Linux users have Python by default, but finding Python is tricky if you don't know where to look. There is a program called Terminal on both Mac and Linux operating systems. This program allows you to exercise a lot of control over your computer in these ways:
- On a Mac, go to Finder | Applications | Utilities and click on Terminal. The terminal application will open up, and you should see a small, white window on your screen.
- Ubuntu users can search for
terminal
on their desktops, and the program will show up in their Start menu. When you click on the terminal, you will see a small, black window on your screen. - The terminal also functions as a Python shell when a command is given to run Python. We will learn about this later.
Text editor
A text editor is a helpful tool for writing and editing Python programs. The terminal is a nice place to test snippets of Python code, but when we want to edit and save the code in order to use it over again, we will need a text editor. Although both Mac and Linux systems come with a text editor, there are some very nice, free editors that have good features. jEdit is one of these editors.
Note
For Mac and Linux, go to http://www.jedit.org/ and download jEdit. Follow the installation instructions.
To successfully complete all of the exercises in this book, you will often need to keep both the terminal and text editor open at the same time on your screen.
This is what the text editor application, jEdit, looks like in Mac and Linux:
For Windows users
Windows users, this setup might require help from your parents. Since Python is not installed by default on Windows, some system adjustments need to be made to successfully run Python on your computer. If you are feeling uncertain about performing these system changes yourself, make sure to ask for help:
- First, you will need to download version 2.7.11 of Python.
Note
Use the official Python website for the latest releases for Windows at https://www.python.org/downloads/release/python-2711/.
With Windows, you need to figure out if you are running 32-bit or 64-bit so that you can download the correct version of Python. To help you to determine which one is correct, visit
http://windows.microsoft.com/en-gb/windows/32-bit-and-64-bit-windows#1TC=windows-7.
Download x86only if your computer is running 32-bit Windows. Most users will download the x86-64 version of Python.
- Choose the executable installer, and you will see the download progress.
- When the download is complete, you will see a prompt to run Python. Click on Run.
- An install prompt will come up, and when it does, look at the bottom of the window and click on the box next to Add Python 2.x to Path. Then, select Install Now.
- Follow the installation instructions. Each step may take a few minutes. Once the installation is done, you will have an icon for Python 2.7.11, which you can find by searching for
Python
in the Windows search bar. This will open a special Python shell from where you can run and test the Python code.
Command prompt
In Windows 10, you will see a terminal called the command prompt. The command prompt is significantly different in Windows than it is on Mac or Linux.
To find the command prompt in Windows 10, perform these steps:
- Go to the search bar at the bottom of the screen and search for
cmd
orcommand
. - When you do, you will see the command prompt desktop app appear. Click on this app to open the command prompt, which looks like this:
Text editor
In Windows, Notepad is the default text editor. However, Notepad++ is a much better substitute.
To get Notepad++, perform these steps:
- Go to https://notepad-plus-plus.org/and download the latest version.
- Once the program has been downloaded, click on Run.
Notepad++ looks like this: