NCSS Challenge

NCSS Challenge 2009

Getting Started on Mac OS X

home | about | faq | rules | resources | register | login
 

Installing Python

Python comes standard on Mac OS X, but the program we recommend you use to get started, which is called "IDLE", is not all that easy to run. To address that, we have created a small wrapper application that you can use to run IDLE easily. You can download it here.

Once it is downloaded, you should see an icon on your desktop that looks like this:

step 1

If instead you see "IDLE.zip", double-click on that file to open it and extract the application. You can leave it on your desktop, or copy it into your Applications folder (or anywhere else that you like).

Checking whether IDLE works

Double-click the IDLE icon to start it, and it should display a window titled "Python Shell" (see below). You can jump straight to the "Running Python" section below.

If instead you see nothing happen, it is probably because some of the code required by IDLE isn't installed on your computer, which might be the case on OS X 10.4 or earlier. In that case, you will need to download and install these two things:

  • Tcl/Tk for OS X (35.1MB). Clicking on this link will bring up a list of mirror sites around the world. Choose OptusNet for downloading in Australia.

If you are running Safari, you will be prompted about the download containing an application, and you should click "Continue":

step 1 tk

You should end up with a new volume mounted, and a Finder window that looks like this:

step 1 tk install

Double-click on "TclTkAquaBI.mpkg" and follow the prompts to install.

After downloading this package, you will again need to "continue" in Safari on 10.4, and you should end up with a folder called " tkinter-8.4-py2.3-macosx10.3" on your desktop. It contains a single file called tkinter-8.4.mpkg. Double-click on that to install.

Running Python

You should now be able to double-click on the IDLE icon again and get the Python Shell window:

step 2 idle

You can type simple programs right into this window:

step 3 hello

When you press enter, the program is run:

step 4 hello result

Hint: you can also use this window as a simple calculator. Try typing in "2 + 8 * 5" (without the quotes) and pressing enter.

!!Writing Python programs

The prompt is fine for programs that you can type quickly and want to run once, but most programs take longer to write and are run multiple times. To write this kind of program, you need to open a separate window:

step 5 new window

Then type in a simple program and choose 'Save As':

step 6 save as

Click on the 'Desktop' icon to save your program on the desktop, and call it 'hello.py'. It is important that you save programs as /something/.py so that OS X can tell that they are Python programs. IDLE doesn't add the '.py' for you, unfortunately.

Once you have saved the program, it will display in colour, and you can run it by choosing 'Run Module' from the Run menu (or by just pressing F5):

step 7 run hello

The results will be displayed in the main IDLE window:

step 8 run results

Now trying changing the program in the editing window into this slightly more complicated one:

step 9 hello name

When you run it (with F5), you will be asked a question in the main IDLE window:

step 10 run with input

Type in your name and press enter, and you should see it in the results that are printed out.

Congratulations! You have just written your first Python program that takes some input and generates some output.

Help!

This guide wouldn't be complete without mentioning one of the most important Python commands, 'help':

step 11 help

This command will give you information about all of the commands available in Python, and even though the output may contain some things that you don't understand, it is good to know that all of this information is at your fingertips.

 
NCSS Challenge 2009, challenge@it.usyd.edu.au