Chapter 9 : Installing and running Python


 Getting started 

By the end of this chapter, learners will have installed Python on their computer and will be able to write and run their first programs.

 Objective 

The aim is to:

  1. Install Python on your computer;
  2. Learn how to edit and run your first program in Python.
 Installing Python 

How you install Python on your computer will depend on the operating system you're using.

To install Python, go to https://www.python.org/downloads/ and choose the version best suited to your operating system: Linux, Windows, macOS...

The following window will appear on your screen.

Installation Python

Follow the instructions to install Python on your computer. Ask for help if necessary.

 The IDLE editor 

You need to be able to send the computer the program or script you want it to run. You do this by typing your script into an editor, from which your text will be "translated" into machine language (interpreted or compiled) for execution by your computer.

In the case of Python you've just installed, the default editor is "IDLE". Other editors can be used, with varying degrees of ease, but we're going to keep things simple and use this one.

To make things easier, we advise you to "pin" the IDLE editor opening command to your taskbar.

 Edit and run your first Python program 

Click on the little icon that has just appeared in your taskbar, and an IDLE editor page will open.

Type 5+3 followed by Enter. The window should display 8 on the next line.

This page communicates your instructions directly to the computer, which then executes them and displays the results. However, when it comes to typing our programs, this reactivity is inadequate. We need to be able to type an entire text before requesting its execution.

To do this, open a new window by clicking on the "File" menu and choosing "New File".

Exécution IDLE 01

A blank page appears, so let's type in our first program... Please note that the layout must be precise, as it is essential for the program to run correctly. You are now in the editing phase.

For ease of communication, click on the "Options" tab and then select "Show Line Numbers".

Exécution IDLE 02

You must now move on to the execution phase. There are two ways of doing this: either press the F5 function key, or select the Run tab in the window and then click on Run Module.

Exécution IDLE 03

The computer will automatically ask you to save your program. Choose the directory where you wish to save your program and the name of your file, ending with ".py".

Exécution IDLE 04

Exécution IDLE 05

Your program will run and provided it contains no errors... you should get this.

Exécution IDLE 06

You can now close the execution window. You'll then find your editing window in the background. Click on one of its edges to bring it back to the foreground. You can then modify your program and request a new run.

Enjoy your discovery and have fun.

Return