Sub topic 4
Installing Python on Windows, macOS, and Linux
This chapter assumes you can open a terminal and run a command, and that you can install software on your own machine. You do not need to know any Python. By the end you will have a supported Python 3 installed through the method that suits your operating system. You will also know how to spot the most common installation mistakes.
What an installation contains
A Python installation is more than one program. It usually includes:
- The interpreter, an executable named
python3,python, orpython.exe, which runs your code. - The standard library, a large set of modules such as
jsonandpathlibthat ship with Python. pip, the tool that installs third-party packages.- On Windows, the
pylauncher, a small program that finds and starts installed interpreters.
Several installations can exist on one machine. Your operating system may carry its own copy, and you may add others. Most installation problems come from running a different interpreter than the one you meant to. Keep that in mind while you work through the steps below.
Choose a method
The fixed choice is the Python version: pick a currently supported Python 3 release from the download page at python.org. The method of installation depends on your system.
Windows
Windows does not ship with a usable Python. You have two common choices.
The python.org installer
- Download the Windows installer (64-bit) from python.org/downloads.
- Run it. On the first screen, tick Add python.exe to PATH. It is off by default in some installer versions.
- Leave Use admin privileges when installing py.exe and the other defaults unless you have a reason to change them.
- Choose Install Now. At the end, you may see an option to disable the path length limit. Enabling it is safe and avoids errors with deeply nested folders.
The installer places the interpreter in your user profile (under AppData\Local\Programs\Python) for a per-user install. It also installs the py launcher.
The Microsoft Store
The Store offers a Python package that installs without administrator rights and updates automatically. It is fine for learning. Its files live in a managed location and are sandboxed in some respects, which can confuse tools that expect a conventional install. If you plan to use an IDE or work on larger projects, prefer the python.org installer.
Windows aliases
Windows ships "app execution aliases" named python.exe and python3.exe. If you have not installed Python, typing python opens the Microsoft Store instead of running anything. If you installed from python.org and python still opens the Store, open Settings > Apps > Advanced app settings > App execution aliases and turn off those two aliases.
macOS
macOS has no supported system Python for your own use. Running python3 on a fresh machine may prompt you to install the Xcode Command Line Tools, which provide an older Apple-supplied Python 3. Do not rely on that copy for your projects. Install your own.
The python.org installer
- Download the macOS universal installer (
.pkg) from python.org/downloads. - Run the package and follow the prompts.
- Python installs under
/Library/Frameworks/Python.frameworkand linkspython3into/usr/local/bin.
This installer also creates a Python 3.x folder in Applications, which contains a script that installs certificates. If HTTPS requests from Python fail with certificate errors, run Install Certificates.command from that folder.
Homebrew
If you already use Homebrew, run:
brew install pythonHomebrew installs python3 and pip3 and updates them when you run brew upgrade. A Homebrew upgrade can move Python to a new minor version. Virtual environments built on the old version may then stop working and need to be recreated. For that reason, some developers prefer the python.org installer or a version manager for project work.
Linux
Most Linux distributions include Python 3 because system tools depend on it. That copy belongs to the operating system. Install packages into virtual environments rather than into it, and do not remove or replace it.
Install or update through your package manager:
# Debian, Ubuntu, and derivatives
sudo apt update
sudo apt install python3 python3-venv python3-pip
# Fedora
sudo dnf install python3 python3-pip
# Arch Linux
sudo pacman -S python python-pipOn Debian and Ubuntu, venv and pip are separate packages. If you skip python3-venv, creating a virtual environment later fails with a message telling you to install it.
Your distribution ships one particular Python version. If it is older than you need, you have these options:
- Use a newer distribution release.
- Use a version manager such as
pyenv, which builds Python in your home directory. - Use a tool such as
uv, which can download and manage Python versions for you. - Build from source. This is rarely necessary.
Avoid adding third-party package archives (PPAs) you do not trust. They replace system packages and can break the distribution's own tools.
Check the installation
Close your terminal and open a new one after installing. An already-open terminal keeps the old PATH and will not see the new Python. Then check the version.
On macOS and Linux:
python3 --version
which -a python3On Windows (Command Prompt):
py --version
py -0
where pythonwhich -a and where list every matching executable on your PATH, in search order. The first one wins. py -0 lists every Python the launcher can find.
To see exactly which interpreter ran and where it lives, ask Python itself:
python3 -c "import sys; print(sys.version); print(sys.executable)"On Windows, use py in place of python3. The sys.executable line prints the full path to the interpreter. This is the most reliable way to confirm which copy you are using.
Common installation errors
| Symptom | Likely cause | Fix |
|---|---|---|
| `'python' is not recognized` (Windows) | PATH box was not ticked, or the terminal is old | Open a new terminal, use `py`, or rerun the installer and choose Modify or Repair |
| `python` opens the Microsoft Store | App execution alias is active | Disable the aliases in Settings, or install Python |
| `command not found: python` (macOS or Linux) | Only `python3` exists | Use `python3`, or inside a virtual environment use `python` |
| Version shown is older than expected | Another install comes earlier on PATH | Run `which -a python3` or `where python` and compare |
| `No module named venv` (Debian or Ubuntu) | `python3-venv` is not installed | `sudo apt install python3-venv` |
| `externally-managed-environment` from pip | Distribution blocks system-wide installs | Use a virtual environment |
| Certificate errors on macOS | Certificates were not installed | Run Install Certificates.command |
Edge cases
- Several versions side by side. On Windows,
py -3.12selects a specific version if it is installed. On macOS and Linux, versioned commands such aspython3.12do the same. - Per-user and all-user installs. A per-user Windows install does not need administrator rights. An all-user install does, and places Python under
Program Files. - Corporate machines. Policy may block installers or the Store. Ask your IT team, or use a portable approach such as a version manager in your home directory.
- Uninstalling. On Windows, remove Python in Settings > Apps. Remove it from the same place you installed it. Deleting folders by hand leaves stale PATH entries.
Exercise
You installed Python on Windows and ticked the PATH option, but python --version in an already-open Command Prompt says it is not recognized. Name two things to try and one command that lists the interpreters Windows can find.
Show answer
First, close the terminal and open a new one, because the old window keeps the PATH from before the install. Second, use the py launcher instead, for example py --version. If python opens the Microsoft Store, turn off the app execution aliases. The command py -0 lists the installed interpreters, and where python shows the executables on PATH in search order.
Exercise
On Ubuntu, python3 -m venv .venv fails even though python3 --version works. What is the most likely cause and the fix?
Show answer
The python3-venv package is missing, because Debian and Ubuntu package it separately from the interpreter. Install it with sudo apt install python3-venv, then run the command again.