Lesson 2, Topic 2
In Progress

The Python Interpreter (Python Installation)

Lesson Progress
0% Complete

Definition of The Python Interpreter

A Python code cannot run by itself; it needs a computer program that executes it. This program is called the Python interpreter.

The Python interpreter is a computer program that permits to execute Python code.

The Python interpreter executes Python code according to the principles and specifications of the Python programming language. We already know that there are multiple versions of the Python language; likewise, there are multiple versions of the Python interpreter. Each version of the Python interpreter implements one and only one version of the Python language. For example, the version 3.10 of the Python interpreter implements the version 3.10 of the Python language.

To be able to run Python code, you must first download and install the Python interpreter on your computer.

Python Installation

Python is distributed to developers through a distribution, which is a software bundle that contains the Python interpreter and other useful tools. There are multiple Python distributions but the most popular one is the standard Python distribution, which can be downloaded from Python’s official website:

Download Standard Python Distribution

Python’s official website provides many versions of the standard distribution. It is recommended to download the latest one, but you can also download an older version. Once the Python distribution is downloaded to your computer, you can start the installation. We will show the installation process for a Windows operating system.

Double-click the downloaded executable file (python-3.9.5-amd64.exe) to start the installation:

Python Executable File

This will open a window with two options (Install Now and Customize installation), and two checkboxes (Install launcher for all users (recommended) and Add Python 3.9 to PATH):

Python Installation
  • Install Now: this option allows to install Python with the default settings. By default, Python will be installed under the AppData folder of your user account:
    C:\Users\<Username>\AppData\Local\Programs\Python\Python39
  • Customize installation: this option allows to customize the installation of Python by selecting which features will be installed and/or changing the default installation folder.
  • Install launcher for all users (recommended): this checkbox is checked by default and allows to install the Python launcher for Windows for every user on the windows system. The Python launcher for Windows is a software that helps in locating and executing the Python interpreter. This software is particularly useful when multiple versions of the Python interpreter are installed on the same computer because it allows to choose a version among them.
    When this checkbox is checked, the Python launcher for Windows will be installed in the Windows directory C:\Windows to be accessible to every user on the computer. The installation in C:\Windows requires administrator privileges, that’s why there is a blue and yellow shield next to the Install Now option.
    For more information, see Appendix A: Python Launcher For Windows.
  • Add Python 3.9 to PATH: this checkbox is unchecked by default but we recommend checking it. It allows to add the directory of the Python interpreter executable (python.exe) to the PATH environment variable of your Windows system.
    For more information, see Appendix B: PATH Environment Variable.

The default installation is recommended for beginners because of its simplicity. However, we will show the steps of both installation types; default and customized.

Default Installation

Note: The following guide assumes that no Python distribution is installed on your computer.

Ensure that the two checkboxes at the bottom of the window are checked, then click on Install Now:

Python Default Installation

A User Account Control window will appear asking you: Do you want to allow this app to make changes to your device? Click Yes:

Python User Account Control

The components of the Python distribution, including the Python interpreter, will be installed one by one:

Python Installation Progress

Then, a Setup was successful message will appear with a Disable path length limit option:

Python Default Installation

In a file system, every directory and file has a path. For example, C:\Program Files\ is the path of the “Program Files” directory. Windows limits the number of characters in a path to 260, but you can change this setting. We recommend that you click on Disable path length limit to remove the 260 character limitation and avoid any issues when running your Python scripts. This will not cause any negative effects on your Windows system.

Note: You can restore the 260 character limitation at any time by changing the Windows registry key Computer\HKEY_LOCAL_MACHINE\SYSTEM\ CurrentControlSet\Control\FileSystem\LongPathsEnabled
from 1 to 0 (0 means that the path is limited to 260 characters, 1 means the opposite):

Windows 260 Character Limitation

A User Account Control window will appear asking you: Do you want to allow this app to make changes to your device? Click Yes:

Python User Account Control

Once the installation is finished, click Close to close the installer:

Python Default Installation

Now, the Python distribution is installed on your computer and you are ready to work with the Python interpreter. Navigate to the installation folder:
C:\Users\<Username>\AppData\Local\Programs\Python\Python39

Standard Python Distribution Installed

This folder contains the Python interpreter, in addition to other files. The Python interpreter can be started from one of two executable files: python.exe or pythow.exe. The python.exe executable is generally used to run programs that have a text-based output, whereas the pythonw.exe executable is suitable for running programs with a graphical user interface (GUI).

When you double-click the python.exe executable, a text-based window will open up. This window is called the Python shell:

Python Shell
Python Shell

Customized Installation

Click on Customize installation to start a customized installation. You can leave the Install launcher for all users (recommended) and Add Python 3.9 to PATH checkboxes as is because you will be able to configure them in the next steps of the installation process:

Python Customized Installation

The next window, named Optional Features, contains the following checkboxes:

Python Optional Features
  • Documentation: this checkbox allows to install the Python documentation locally on your computer. This documentation is the same as the one on Python’s official website, and it will be stored on your computer as a single .chm file.
  • pip: this checkbox allows to install the Package installer for Python, abbreviated as pip, which is a software that helps you download, install, and uninstall Python packages. Python packages are software bundles that extend the functionality of an existing Python installation. The pip will be installed in this folder: \Python\Python39\Scripts.
  • tcl/tk and IDLE: this checkbox allows to install IDLE, Tcl/Tk , and tkinter. IDLE is a code editor for Python that requires Tcl/Tk and tkinter to function properly. Tool Command Language/Toolkit, abbreviated as Tcl/Tk, is both a scripting language and a graphical user interface toolkit (GUI toolkit) for building GUI applications. Tkinter, short for Tk interface, is a Python package that serves as an interface between Python and the Tcl/Tk toolkit.
  • Python test suite: this checkbox allows to install the Python test suite, which is a collection of test cases that can be used to test Python programs. The purpose of testing a Python program is to ensure that it is working as intended. The Python test suite will be installed in the Python standard library, more precisely in this folder: \Python\Python39\Lib\test.
  • py launcher: this checkbox allows to install the Python launcher for Windows for the current user of the windows system. The launcher will be installed in this folder:
    C:\Users\<Username>\AppData\Local\Programs\Python\Launcher.
    If the for all users (requires elevation) checkbox is also checked, the launcher will be installed in the Windows directory, C:\Windows, to be accessible to every user on the windows system. The installation in C:\Windows requires elevation (i.e. requires administrator privileges). Checking the py launcher and for all users (requires elevation) checkboxes together has the same effect as checking the Install launcher for all users (recommended) checkbox in the first window of the installation.
    Check this checkbox if you intend to install more than one version of the standard Python distribution in the future. Otherwise, leave it unchecked because you don’t need the Python launcher if you have only one version installed.
    For more information, see Appendix A: Python Launcher For Windows.

Choose your optional features then click the Next button. The next window, named Advanced Options, contains the following checkboxes:

Python Advanced Options
  • Install for all users: this checkbox allows to install the Python distribution for every user on the windows system. If you check this checkbox, the Precompile standard library checkbox will also be checked and the Customize install location at the bottom of the window will change to C:\Program Files\Python39 (installing in C:\Program Files\ requires administrator privileges).
    Note: The Install for all users checkbox mustn’t be confused with the Install launcher for all users (recommended) checkbox. The first installs the whole Python distribution whereas the second installs just the Python launcher for Windows.

  • Associate files with Python (requires the py launcher): this checkbox allows to change the settings of Windows default apps by associating Python file extensions with the Python launcher for Windows. For example, the .py file extension will be associated with the Python launcher. This will permit to execute Python scripts by just double-clicking them.
    Note: The association of files with the Python launcher requires the installation of this latter. Therefore, this checkbox will be grayed out if the py launcher checkbox in the previous window was not checked.
Python Windows File Association
  • Create shortcuts for installed applications: this checkbox allows to create shortcuts in the Windows Start menu for the IDLE code editor, Python shell, and Python documentation:
Python Windows Start Menu
  • Add Python to environment variables: this checkbox allows to add the directory of the Python interpreter executable (python.exe) to the PATH environment variable of your Windows system. This checkbox is the same as Add Python 3.9 to PATH in the first window of the installation, so checking one of the checkboxes will automatically check the other.
    For more information, see Appendix B: PATH Environment Variable.
  • Precompile standard library: this checkbox allows to precompile the Python standard library. Compilation and the Python standard library will be defined later in this course.
  • Download debugging symbols: Debugging is the process of finding and fixing bugs, i.e. errors, in computer programs. This checkbox allows to download the debugging symbols of the current Python distribution (each distribution version has its own debugging symbols). Debugging symbols are .pdb files that facilitate the debugging process (28 files in total).
  • Download debug binaries (requires VS 2017 or later): this checkbox allows to download the debugging binaries of the current Python distribution, which are files with these extensions: .exe, .dll, .pdb, .pyd, and .lib (53 files in total). Debugging symbols and binaries are useful for the users of Visual Studio 2017 (or later) to debug Python and C/C++ codes simultaneously.
    Note: Debugging symbols and binaries are destined for advanced Python developers.
  • Customize install location: this text field allows to specify a new installation location. We recommend that you keep the last two directories of the default installation location (i.e. keep \Python\Python39). For example, if you want to install Python under the C: drive, then the new installation location should be: C:\Python\Python39, if you want to install it under C:\Program Files\ then the location should be C:\Program Files\Python\Python39, and so on. This is because it is probable that you will install more than one Python version on your computer, and it is a good idea to gather them under the same parent directory Python.

Choose your advanced options then click on Install. The next installation steps are similar to the ones described in default installation.

If you installed Python without one or more of the features described above, then you can add it/them at any time. Navigate to the executable file of the Python distribution that you want to modify (python-3.9.5-amd64.exe in our case) and double-click it. This will open a window with three options: Modify, Repair, and Uninstall:

  • Modify: allows to add one or more of the features described above.
  • Repair: allows to fix the Python installation in case it is not working properly.
  • Uninstall: allows to remove the entire Python installation.
Python Modify Installation

Click on Modify. This will open the Optional Features window described above. Select the feature(s) that you want to add and complete the installation process:

Python Optional Features

Note: It is a good idea to keep the downloaded executable file of the Python distribution on your computer because you may need it in the future, especially when you want to uninstall this distribution. In fact, third-party uninstallers can leave files behind, and this can prevent the proper installation of other Python distributions.