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:
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.
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:
Open the terminal (in Windows, press
Win + R
, typecmd
, and pressEnter
).Enter
python --version
and pressEnter
. If Python is installed, you should see the version number, like this:
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).
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.
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:
This command will list all installed Python versions, like this:
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
?
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:
- Open the Control Panel (press
Win + R
, typecontrol
, and pressEnter
). - Click on System and Security.
- Click on System.
- Click on Advanced system settings.
- Click on Environment Variables.
- In the User variables section, look for the
Path
variable and click on Edit. - 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:
To install a package, use the following command in the terminal:
For example, to install the pandas
package, run:
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
.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.