UW CSE logo uw

CSE 142: Computer Programming I, Autumn 2007

arrow CSE Home arrow About Us arrow Search arrow Contact Info

Installing Python

Like Java, you will need at most only two pieces of software: the Python environment and some text editor. Depending on your operating system, you'll use different instructions to install Python.

Windows
Mac OSX
Linux

If you encounter problems trying to set up Python, contact Scott (tannewt AT cs.washington.edu) or Ian Gienger (igienger AT cs.washington.edu) for help and suggestions.


Windows

Windows does not come with Python pre-installed, so you will have to download and install it.

Step 1. Install Python

Python v2.5.1 Installer

Click the link above to download the Python installer. Once downloaded, run the program to install Python.

Step 2. Install TextPad (Optional)

TextPad Download

After installing Python, you will have a basic editor called IDLE. However, you can install a nicer editor instead; we suggest TextPad. Download TextPad from the link above and install it.

Step 3. Configure TextPad (Optional)

Python Syntax for TextPad

Next, download the Python Syntax .zip file and extract the contents into the "Samples" folder in your TextPad installation directory. For example, if you installed into

C:\Program Files\TextPad\
, extract the contents into
C:\Program Files\TextPad\Samples
. Next, open TextPad and run "Configure -> New Document Class...". For the "Document Class Name", enter
Python
and click Next. For "Class Names" enter
*.py
and click Next. Check "Enable Highlighting" and choose
PythonV2.4.syn
from the dropdown list, then click Next and Finish.

After that, run "Configure -> Preferences" and do the following:

Click OK and you're done!

Step 4. Using Your Editor

TextPad

To use TextPad, make sure you have an empty document; create a new one if necessary (CTRL+N). Next, save your empty document (CTRL+SHIFT+S) as a *.py file -- for example, "greeneggs.py". Now you can type your Python code as usual with syntax highlighting.

To run your Python code, go to "Tools -> External Tools -> ...\python.exe $File" (or press CTRL+1) and the output will be displayed in a DOS window.

IDLE

IDLE is an interpreter/editor combo called found under "Start -> Programs -> Python 2.5 -> IDLE". To create a new Python script, go to "File -> New Window" (CTRL+N). Here you can type out your Python code, save it, and then run it by selecting "Run -> Run Module" (F5). A small benefit of the IDLE environment is that you can test Python commands in the Python Shell window ("Run -> Python Shell"), which contains the Python interactive interpreter.

Step 5. Using the Python Interpreter

To use the Python interpreter alone, run "Start -> Programs -> Python 2.5 -> Python (Command Line)". Here you can type Python commands into the window interactively.

Useful Extras

To enable the command

python
from the command line, follow these steps.
  • 1) Right-click "My Computer" and select "Properties"
  • 2) Choose the "Advanced" tab (Screenshot)
  • 3) Click on "Environment Variables" (Screenshot)
  • 4) If making this change for one user only, either "Edit" or create the "PATH" variable under the "User variables" section. If it already exists, append
    ;C:\Python25
    (changing
    ;C:\Python25
    to whatever your installation directory is). If it doesn't already exist, type in
    %PATH%;C:\Python25
    , once again substituting your installation directory (Screenshot)
  • 5) If making this change systemwide, "Edit" the "PATH" variable under the "System variables" section. Append
    ;C:\Python25
    to the end, substituting your Python installation directory
  • 6) Exit out, saving your changes

Mac OS X

Luckily, Python comes pre-installed on Macs. However, it doesn't come bundled with an editor, so we recommend installing Smultron, a text editor.

Step 1. Install Smultron

Smultron Homepage

First, go to the Smultron Homepage and download the Latest Version from the Download section in the top right.

Step 2. Configure Smultron for Python

Although Smultron will work fine without configuration, a single configuration option will make life a little easier.

Go to "Tools -> Handle Commands -> Show Commands Window" (⌘B) and select "Other" under the Collections column. Next, click "New Command" in the top right. For a name, put "Run Python Script". In the box below, type

/usr/bin/env python %%p
. Optionally, double-click the shortcut field to create a shortcut to run your script. If everything was done correctly, it should look like this screenshot.

Step 3. Using Your Editor

Smultron is easy to use. First, create a new document (⌘N). Next, save your empty document (⌘S) as a .py file -- for example, "greeneggs.py". Finally, type your Python code as you normally would and it will show up with syntax highlighting.

To run your Python code, select "Tools -> Commands -> Other -> Run Python Script", or optionally use your shortcut keybind if you made one in the previous step.

Step 4. Using the Python Interpreter

To use the Python Interpreter, open Terminal and type

python
to start it. Terminal is located in "Applications -> Utilities -> Terminal".


Linux

Chances are, if you're using a Linux distribution you probably have Python already. To check, open a Terminal (aka Command Line) and type

python
. If you already have Python installed, this will pull up a Python Interpreter; otherwise, follow the instructions to get Python on this page.