2  Installing Python

There are several ways to install Python on your computer (see some options here). We recommend using the official Python installer. Follow the links below to download the installer for your operating system:

After downloading the installer, follow the installation instructions. Make sure you check the box that says β€œAdd Python to PATH” during the installation process. This will allow you to run Python from the command line.
What is PATH?

The PATH is an environment variable on your computer that specifies a set of directories where executable programs are located. When you run a command in the terminal, the operating system searches for the executable file in the directories listed in the PATH variable. By adding Python to the PATH, you can run Python from the command line without specifying the full path to the Python executable.

2.1 Troubleshooting

Below are some tips to help you troubleshoot common issues when installing Python.

Warning

These tips are fine-tuned for Windows. If you are using a different operating system, you may need to adapt the instructions accordingly.

2.1.1 Is Python Working?

To check if Python is installed on your computer:

  1. Open the terminal (in Windows, press Win + R, type cmd, and press Enter).

  2. Enter python --version and press Enter. If Python is installed, you should see the version number, like this:

    C:\Users\UserName>python --version
    Python 3.13.0

If you see an error message, Python may not be installed correctly. In this case, you can try reinstalling Python by following the instructions above (especially the part about adding Python to the PATH).

What is a Terminal?

A terminal is a text-based interface that allows you to interact with your computer using text commands. It is also known as a command-line interface (CLI). You can use the terminal to run programs, manage files and directories, and perform other tasks.

Windows Terminal. To open the terminal, press Win + R, type cmd, and press Enter. Or, search for cmd (Command Prompt) in the Start menu.

2.1.2 Is The Correct Python Version Running?

If you installed Python through the official installer from python.org, you can use the py command to select the Python version you want to use.

To check the installed Python versions, run the following command in the terminal:

py --list

This command will list all installed Python versions, like this:

C:\Users\User>py --list
 -V:3.13 *        Python 3.13 (64-bit)
 -V:3.12          Python 3.12 (64-bit)

The asterisk (*) indicates the default Python version. If you want to run Python 3.12, use the following command, where <command> is the Python command you want to run (e.g., --version, --help, etc.):

py -3.12 <command>
What is py?

The installation will also add the py command to your system. The difference between py and python is that py is a launcher that allows you to run different Python versions installed on your computer. For example, you can run py -3.12 to run Python 3.12, or py -3.13 to run Python 3.13.

Sometimes, other versions of Python may be installed on your computer, and the python command may still point to a different version. This can occur if Python was installed using a different method, such as the Microsoft Store. In this case, you will need to modify the PATH variable to point to the desired Python version:

  1. Open the Control Panel (press Win + R, type control, and press Enter).
  2. Click on System and Security.
  3. Click on System.
  4. Click on Advanced system settings.
  5. Click on Environment Variables.
  6. In the User variables section, look for the Path variable and click on Edit.
  7. Add the path to the Python version you want to use at the beginning of the list. For example, if you want to use Python 3.13, add the following paths (click on New for each):
    • C:\Users\UserName\AppData\Local\Programs\Python\Python313
    • C:\Users\UserName\AppData\Local\Programs\Python\Python313\Scripts
    • Make sure to replace UserName with your actual username.

There might be other Python paths in the list. Make sure the path to the desired Python version is at the beginning of the list. Click OK to save the changes.

2.2 Installing Python Packages with pip

pip is a package manager for Python that allows you to install and manage Python packages. First, to update pip to the latest version, run the following command in the terminal:

py -3.13 -m pip install --upgrade pip

To install a package, use the following command in the terminal:

pip install package_name

For example, to install the pandas package, run:

pip install pandas

Example of installing the pandas package using pip. The command py -m pip install pandas will install the pandas package in the default Python version. Running just py -m pip install pandas would achieve the same result. Once pandas is installed, we update pip by running pip install --upgrade pip.
What is a Python Package?

A Python package is a collection of Python modules that can be used to add functionality to your Python programs. Packages are a way to organize and distribute Python code, making it easy to reuse code and share it with others. In this course, we will use several Python packages, including:

  • numpy: Numerical computing library.
  • pandas: Data manipulation and analysis library.
  • matplotlib: Plotting library.
  • pytest: Testing framework.