Sub topic 4
Installing Python on Windows, macOS, and Linux
This chapter assumes you can open a terminal or command prompt and that you have permission to install software on your computer. You do not need to know any Python yet. The earlier chapters on choosing a version and on terminal basics are enough. Use a current Python 3 release that is still supported. Python 2 is no longer maintained.
Pick an installation route
Each operating system offers more than one way to install Python. Choose one route and stay with it. Mixing routes is a common cause of the "wrong Python" problems covered later in this tutorial.
Windows
Download the installer from the Downloads section of python.org and run it. On the first screen of the classic installer, select Add python.exe to PATH before you click Install. PATH is the list of folders your terminal searches when you type a command. If that box is unchecked, the terminal will not find Python by name.
Recent Python releases may instead offer the Python install manager. It provides the py launcher, which finds an installed Python for you. Follow the prompts the installer shows.
When the installer finishes, open a new terminal window. Windows terminals read PATH only when they start, so a window that was already open will not see the change.
macOS
You have two common options:
- python.org installer. Download the macOS package from python.org and open it. It installs Python 3 and a
python3command. - Homebrew. If you already use the Homebrew package manager, run
brew install python.
Do not rely on any Python that came with the operating system. Apple's developer tools may provide a python3, but it is tied to the system and may be older than you want.
Linux
Most distributions include Python 3, but you may be missing pieces. On Debian and Ubuntu, the venv module and pip ship as separate packages:
sudo apt update
sudo apt install python3 python3-venv python3-pipOn Fedora, use:
sudo dnf install python3 python3-pipThe system Python is used by parts of the operating system. Install packages into a virtual environment, which a later chapter covers, instead of changing the system Python.
Confirm the result
Open a new terminal and ask for the version:
python3 --version
# On Windows, use: py --versionYou should see a line such as Python 3.12.4. The exact numbers depend on the release you installed. If you see "command not found" or "not recognized", Python is missing or not on PATH. The next chapter explains how to fix that.
Common installation mistakes
| Mistake | Effect | Fix |
|---|---|---|
| Skipping the PATH option on Windows | The terminal cannot find `python` | Re-run the installer and choose the PATH option, or use `py` |
| Testing in a terminal that was open during install | The old PATH is still in use | Close the terminal and open a new one |
| Installing from several sources | Two Pythons exist and the wrong one runs | Keep one route and remove the extra install |
| Missing `python3-venv` on Debian or Ubuntu | Creating a virtual environment later fails | Install the package with `apt` |
Exercise
You installed Python on Windows with the python.org installer, but a terminal window that was already open still says "python is not recognized". What is the most likely cause, and what should you try first?
Show answer
The open terminal started before the installer changed PATH, so it still has the old list of folders. Close it, open a new terminal, and run py --version again. If that still fails, re-run the installer and select the option to add Python to PATH.
Exercise
Why should you avoid replacing the system Python on Linux?
Show answer
The operating system's own tools may depend on it. Replacing or removing it can break them. Install your own packages in a virtual environment instead.