Installing Python

This course uses the python interpreter. This program may already be available on your computer. If not, you'll have to install it.

The textbook's home page: introcs.cs.princeton.edu/python/home has detailed instructions on installing the interpreter, plus all the libraries used in the course.

However, to get things started, you can simply install the interpreter. It's available on python.org's download page: www.python.org/download/releases/2.7.8

Go to that page, and choose the installer that works with your machine. Specifically,

  1. for a 32-bit Windows machine: www.python.org/ftp/python/2.7.8/python-2.7.8.msi
  2. for a 64-bit Windows machine: www.python.org/ftp/python/2.7.8/python-2.7.8.amd64.msi
  3. for a 32-bit Mac with OS X 10.5 and later: www.python.org/ftp/python/2.7.8/python-2.7.8-macosx10.5.dmg
  4. for a 64-bit Mac with OS X 10.6 and later: www.python.org/ftp/python/2.7.8/python-2.7.8-macosx10.6.dmg
Each of these packages includes the python interpreter, plus many libraries, and also the "IDLE" development environment, which lets you enter python programs, run them, and see the results.

Running The Interpreter through IDLE

The python program comes with its own text editor and debugger. It's called IDLE. Here is how to find it:

Using IDLE

IDLE lets you run python programs in two ways: interactively, and from files. You will mostly use files in your assignments; the interactive shell is for short exploratory bits of code.

The interactive IDLE shell

This is simple. Just type python code into the window that appears when you first run IDLE, and see the interpreter respond. Later, you might open other IDLE windows. To return to this first interactive shell, pull down the Window menu, and choose Python 2.7.xx shell

Running program files with IDLE

You can create program files in several ways: You can use a proper text editor like Notepad++ or TextWrangler (see here for details), or you can use IDLE's text editor, which is not too bad.

To make a new program file with IDLE, just choose File, New File. Type your code into the window, and save it when finished. Make sure to save the file into the folder where you keep your programs! Notice that IDLE will automatically add a .py ending to your file's name.

If you made the program file with another editor, just use File, Open... to access it with IDLE.

To run the program you just opened, choose Run, Run Module, or hit the F5 key.

Running a shell

Later in the course, we may use the python interpreter from the command line. Don't try this yet. Details are available here .