Installing and Using Python

This page will show you how to install Python on different operating systems and use the default integrated development environment (IDE) called IDLE to write Python programs.

There are two stable versions of Python currently available - Python 2.7 and Python 3.2. In this wiki, we will cover Python 2.7.

Installation
First, download Python from one of the following links. If you do not know which link to download and you are using Windows XP and above, chances are you should download the 64-Bit version.

Python 2.7.2 for Windows 64-Bit Download

Python 2.7.2 for Windows 32-Bit Download

Open the installer after the download has finished and follow the given instructions.

The default installation path is C:\Python27 - you may change this to whatever you like during installation but remember where you saved it.

The installer will ask you which packages to include. By default, the installer includes everything. It is recommended that you do not change it in case you need any of these tools later.

Opening IDLE
Once installed, go to Start > All Programs. You will see a new, highlighted folder labeled "Python 2.7".

Inside this folder is a program called IDLE. Open it. It should pop up a window that looks similar to the following:



Below, we will show you how to write your first program in IDLE. Click here to jump there.

Installing Python and IDLE on Mac
Although Macs come with Python already installed, it may be outdated and will not include IDLE, which we use to edit our Python scripts in this wiki.

Installation
Download Python from the following links:

Python 2.7.2 for MacOSX 10.7 Lion

Python 2.7.2 for MacOSX 10.3 Panther to MacOSX 10.6 Snow Leopard

After downloading, go to your download folder and unzip the file.

Then, open the resulting .dmg file (it's name should be similar to the zip). A window will pop-up showing the contents of the mounted .dmg file, which are 3 text files and a package file.

Run the package file and follow the instructions to install Python 2.7.2.

Opening IDLE
Shortcuts to Python are installed in your Application folder under Python 2.7.

To open IDLE, go to that folder and open the file labeled IDLE within it. This should open a shell that looks like the following:



Next, you will write your first program using the IDLE editor.

Writing Your First Python Program in IDLE
When you first open IDLE, it pops up a window known as a "shell". This shell takes Python code directly and interprets it.

You can test this yourself. In the shell, type: 2 + 7 This will print "9".

Now, you will learn to make a Python script, which is a file that is run by the Python interpreter all at once.

Making a Python script is not done in a shell, but in an editor. IDLE also has a built-in editor, but you need to open a new editor window.

To do this, go to File > New Window or press Ctrl + N (⌘N on Mac)

As you can see, this window looks a bit different from a shell. First, none of the stuff about versions or copyrights are printed in the window. Also, if you press "Enter", it just makes a newline and does not execute any code. You can also go back to previous lines and change them.

Let's write our first "Hello World" program.

At the top of your program file, type:

hello = "Hello World" print hello Let's break down each part of your program before we run it: This is called a "comment". Code that is commented is not run at all. Rather, it is there just to let programmers leave reminders for themselves, and anyone else who may use the code, for later. In this wiki, we will use comments often to explain what is happening in the code examples we give you. More on comments can be found here. hello = "Hello World" This assigns the variable "hello" to the string "Hello World". You will see more on assigning variables in this section. print hello This will print what is contained in "hello" (i.e. "Hello World") to the screen.
 * 1) My first hello world program!
 * 1) My first hello world program!

You'll notice that both the shell and the editor help you write your Python syntax properly by highlighting words differently.

Save your file as "hello.py". The ".py" is important for telling your computer what kind of file it is. The "hello" is the name of your program. You can change "hello" to whatever you like for future programs. IDLE will not allow you to run your script without saving it first.

To run your script, go to Run > Run Module or press F5.

The shell window will then come to the front and have printed "Hello World".

Congratulations! You just ran your first Python script!