COMP 1001: Introduction to Programming

Setting Up Your Computer

Python and IDLE

Pranjal Patra
Department of Computer Science, Memorial University of Newfoundland

Memorial University of Newfoundland

Before you start

The workbooks on this site run Python inside your browser, so nothing needs to be installed to use them. To write and run your own programs on your own computer, you need Python installed. This page installs Python 3 and IDLE, the editor that comes with it, and runs a first script. Pick the section for your operating system.


Windows

Install Python

  1. Go to python.org/downloads.
  2. Download the latest Python 3 installer for Windows.
  3. Run the installer.
  4. On the first installer screen, check Add python.exe to PATH.
  5. Click Install Now.
Do not skip step 4

The Add python.exe to PATH box is unchecked by default and is easy to miss. Without it, typing python in a terminal will not find Python. If you already installed without it, run the installer again and choose Modify.

Open IDLE

You will first see the Python Shell.

Write a script

  1. In IDLE, click File → New File.
  2. Type:
    print("Hello, world!")
  3. Click File → Save.
  4. Save it as:
    hello.py

Run it

The output appears in the Python Shell:

Hello, world!

macOS

Install Python

  1. Go to python.org/downloads.
  2. Download the latest Python 3 installer for macOS.
  3. Open the downloaded .pkg file.
  4. Follow the installer steps.

Python installed from python.org normally includes IDLE.

Open IDLE

Write a script

  1. Click File → New File.
  2. Type:
    print("Hello, world!")
  3. Click File → Save.
  4. Save it as:
    hello.py

Run it

You should see:

Hello, world!

The Shell and a Script

The window showing:

>>> 

is the Python Shell. It is useful for trying individual Python commands: type one line, press Enter, and see the result at once.

For programs with several lines, use a script instead:

File → New File⟶ write code⟶ save as .py⟶ Run Module

A script is saved as a file, so you can fix it and run it again. What you type in the Shell is gone when you close the window.