0.5 Installing Python from the command line¶
Suggested time: 30–45 minutes · You need: Chapters 0.3 and 0.4, and permission to install software
What you will do¶
Install Python, and later update it or add a second version, by typing commands instead of clicking through installers. By the end of this chapter you will be able to:
- explain what a package manager for software is;
- install Python from the command line on Windows, macOS or Linux;
- explain what the
PATHis and check that Python is on it; - keep more than one version of Python and choose between them.
Before you start: ask first
Installing software on a school computer usually needs permission, and sometimes an administrator password. Check your school's IT rules, or ask your teacher. On your own computer, the commands below are safe to use.
These commands change over time
Installers and package names are updated from time to time. The commands below were current in September 2026. If one doesn't work, check the official page it comes from (named in each section).
Key vocabulary¶
| Term | Meaning | Example |
|---|---|---|
| Package manager (for software) | A tool that finds, downloads, installs and updates programs for you | winget (Windows), Homebrew (Mac), apt (Linux) |
| Package ID | The exact name a package manager uses for a program | Python.PythonInstallManager |
PATH |
The list of folders the shell searches when you type a command | Python's folder must be on it |
| Runtime | An installed copy of Python that can run programs | Python 3.14 |
The big idea: installing with commands¶
Clicking through an installer works once, on one computer. A command does the same thing every time, can be written in instructions for a whole class, and can be run again later to update. That's why professional developers install their tools with package managers.
Concept: the PATH
How it works: when you type a command such as python3, the shell doesn't search the whole disk. It looks
through a list of folders called the PATH, in order, and runs the first matching program it finds.
Why it matters: if Python's folder isn't on the PATH, the shell says the command isn't recognised, even though
Python is installed. If two versions are on the PATH, the one listed first wins.
Where else it's used: every command you type (git, pip, cd on some systems) is found the same way.
where (Windows) and which (Mac/Linux) show you which one the shell picked.
Windows: the Python install manager¶
Since Python 3.14, the Python developers recommend the Python install manager for Windows. It installs Python runtimes, keeps them up to date, and lets you keep several versions side by side. (The older one-version installer is deprecated and will not be produced for Python 3.16 onwards.)
Step 1: install the install manager¶
winget is Windows' own package manager, included with current versions of Windows 10 and 11. Open Command Prompt
or PowerShell and type:
What's happening?
winget install downloads and installs a program. --id gives the exact package ID, and -e means
exact match, so winget can't pick a similarly named package by mistake. You can also get the install manager
from the Microsoft Store, by searching for Python Install Manager.
Close the terminal and open a new one, so it picks up the new PATH.
Step 2: install a Python runtime¶
py install downloads a runtime; py list shows the runtimes you have. To see every version available, type
py list --online.
Step 3: check it works¶
If something seems wrong
py install --configure runs a configuration checker, which looks at your settings (including the PATH) and
suggests fixes.
Check the details on python.org
The install manager is new, and its commands may gain options over time. The documentation page Using Python on Windows on docs.python.org is the authoritative reference.
macOS: Homebrew¶
Homebrew is the most widely used package manager for macOS.
Step 1: install Homebrew (once)¶
Go to brew.sh and follow the one-line install instruction on the front page. Copy it from brew.sh itself rather than from a book or a website, because it contains a web address that may change.
Step 2: install Python¶
What's happening?
brew install python installs the current Python 3 and makes it available as python3. Homebrew will also update
it for you: brew upgrade python.
Homebrew's Python and pip
Homebrew's Python won't let pip install libraries into itself. You will see an
externally-managed-environment error. This is deliberate. Chapter 0.6 shows the fix: a virtual environment
for each project.
You can also install Python on a Mac with the installer from python.org (Chapter 0.2). Either is fine, but use one method, not both.
Linux¶
Most Linux distributions already include python3. You may need to add pip and venv:
sudo runs the command as an administrator and will ask for your password.
Step 4: which Python is the shell using?¶
Checkpoint
A new terminal window prints the Python version you installed, and where/which shows where it lives.
Several versions side by side¶
Sometimes you need an older Python, for example if a library doesn't support the newest one yet.
One project, one version
If a project needs a particular Python version, create its virtual environment with that version (Chapter 0.6). The project then always uses it, whatever your default is.
Troubleshooting¶
| What you see | What to try |
|---|---|
'winget' is not recognized |
Your Windows may be too old, or App Installer may be missing. Install App Installer from the Microsoft Store, or use the Microsoft Store to get the Python install manager directly. |
'py' is not recognized just after installing |
Close the terminal and open a new one. If it still fails, run py install --configure from the Start-menu entry, or reinstall. |
brew: command not found |
Homebrew isn't installed, or the terminal hasn't picked it up. Follow the Next steps printed at the end of the Homebrew install, then open a new terminal. |
| Access denied / requires administrator | You don't have permission on this computer. Ask your teacher or IT team. |
Check your understanding¶
- What is a package manager, and why is installing with one better than clicking through an installer?
- Python is installed, but typing its command says it isn't recognised. What is the most likely cause?
- What does the
-edo inwinget install --id Python.PythonInstallManager -e? - How would you run a program with Python 3.13 when your default is 3.14, on Windows?
Answers
- A tool that finds, downloads, installs and updates software. Commands are repeatable, can be shared as instructions, and can update the software later.
- Python's folder isn't on the
PATH, or the terminal was opened before the install and hasn't picked up the newPATH. - It asks for an exact match on the package ID, so winget can't install a similarly named package by mistake.
py -3.13 program.py.
Summary¶
- Windows:
winget install --id Python.PythonInstallManager -e, thenpy install 3.14. - macOS: install Homebrew from brew.sh, then
brew install python. - Linux: use the distribution's package manager, for example
sudo apt install python3 python3-venv. - The shell finds commands using the PATH;
whereandwhichshow which copy it found. - Open a new terminal after installing anything.