This article takes you through the steps to install Python with IDLE on Windows, Mac and Ubuntu. You will also learn to create a new Python script in IDLE and run it.
Step One: Download and Install Python IDLE
Windows
Python installer for Windows can be downloaded from the Python downloads page. Though you can download and install any version of Python, in our example, we are going to download and install Python 3.7.4, which is the latest version available now for Windows.
Go to https://www.python.org/downloads/ and download the installer.
To start the installation, double-click on the downloaded .exe file and then click the Run button when prompted.
The installation wizard launches.
Choose the Install Now option. If you want to run Python by typing ‘python’ in the Windows command line prompt, select the Add Python to PATH check box.
Once the installation finishes, click the Close button.
Mac OS
Now, let’s look at how to install Python for Mac OS.
Python installer for Mac can be downloaded from the Python downloads page. Though you can download and install any version of Python, in our example, we are going to download and install Python 3.7.4, which is the latest version available now for Windows.
Go to https://www.python.org/downloads/ and download the installer.
To start the installation, double-click on the downloaded .pkg file and then click the Continue button when prompted.
Click the Continue button for every other dialog window of the install wizard and when asked to agree to the license agreement, click the Agree button to accept it.
Click the Install button to install.
After the installation has completed, a confirmation screen appears. Click the Close button to finish the installation process.
Ubuntu (and other Linux systems)
Note: The steps below have only been tested on Ubuntu. If there’s any errors for other Linux systems, please leave a comment here.
Before we download Python for Ubuntu, we should make sure that our list of repository packages and Personal Package Archives are up-to date.
First, open the terminal.
To do that, click on the “Show Applications” button on the bottom left corner of the screen and type “terminal” without quotation marks to search for terminal.
In the terminal that opens up, type the following command and press the Enter key:
Ubuntu and other Debian based Linux system: sudo apt-get update
Red Hat based Linux: yum update
Suse based Linux systems:
Command to refresh the repository: sudo zypper refersh
Command to update: sudo zypper update
Enter your username and password when prompted and press the Enter key.
Wait till the update completes.
Next, type the following command (whichever applicable) into the terminal and press the Enter key:
Ubuntu and other Debian based Linux system: sudo apt-get install idle-python3
Red Hat based Linux: sudo yum install idle-python3
Suse based Linux systems: sudo zypper install idle-python3
Wait till the installation completes.
Step 2: Launch IDLE
Windows
To launch IDLE in Windows, click the Windows Start button and from the Programs list, select IDLE. Alternatively, you can also look for IDLE in the Programs list by typing “IDLE” without quotation marks into the search box.
Mac OS
To launch IDLE in Mac OS, select Go >> Applications in Finder and search for “IDLE” by typing “IDLE” without quotation marks into the search box.
Alternatively, click the Launchpad icon in the Dock to open the Launchpad and then search and locate IDLE.
Ubuntu
To launch IDLE in Ubuntu, click on the “Show Applications” button on the bottom left corner of the screen and type “IDLE” without the quotation marks to search for IDLE.
Step 3: Using the Python Shell
After launching IDLE, you’ll be presented with the Python Shell window. (Note: The steps below are the same for all three operating systems.)
The Python Shell allows us to use Python in interactive mode. This means we can enter one command at a time. The Shell waits for a command from the user, executes it and returns the result of the execution.
Let’s try that.
On the Python Shell window that opens up, type
print("hello world!")
and then press the Enter key.
Step 4: Create a new Python script and run it
The Python Shell is a very convenient tool for testing Python commands, especially when we are first getting started with the language. However, if you exit from the Python Shell and enter it again, all the commands you type will be gone. In addition, you cannot use the Python Shell to create an actual program. To code an actual program, you need to write your code in a text file and save it with a .py extension. This file is known as a Python script.
In this example, we will see how to create a Python script that prints the text “Hello World”.
First, launch IDLE. From the Python Shell window that appears, select File >> New File.
Type the following code into the text file that appears (not the Shell):
#Printing the words "Hello World!"
print("Hello World")
To run the script, press the F5 key or select Run >> Run Module.
In the Shell window that appears, Python will now print the words “Hello World”.
Done? Congratulations! You have just successfully written and run your first Python program.
Note that the line #Prints the Words “Hello World” in the Python script above is actually not part of the program. It is a comment written to make our code more readable for other programmers. This line is ignored by the Python interpreter. Python treats any line of text that follows the # symbol as comments.