Concept Explanation
Before you can run a single line of Python, your computer needs the Python interpreter — the program that reads your .py files and executes them. Many systems ship with a version already, but it is often old and sometimes reserved for the operating system's own use, so installing your own is the safer path.
Which version?
Always install the latest stable Python 3.x. Python 2 reached end of life in 2020 and receives no security fixes. If a tutorial uses print "hello" without parentheses, it is Python 2 and you should ignore it.
Installing by platform
| Platform | Recommended method | Notes |
|---|---|---|
| Windows | Installer from python.org | Tick "Add python.exe to PATH" on the first screen |
| macOS | brew install python | The pre-installed Python is for system use — don't touch it |
| Linux | sudo apt install python3 python3-pip | Most distributions include it already |
Verifying the install
Open a fresh terminal and run:
python --version
You should see something like Python 3.12.4. On macOS and Linux you may need python3 instead — those systems keep python pointing at the legacy version, or leave it undefined entirely.
Check the package installer too, since you will need it constantly:
pip --version
The interactive shell
Typing python with no filename drops you into the REPL (Read-Eval-Print Loop) — a prompt where each line runs immediately:
>>> 2 + 2
4
>>> name = "Ada"
>>> print(f"Hello, {name}")
Hello, Ada
>>> exit()
This is the fastest way to test a small idea. Nothing you type here is saved, which makes it perfect for experiments and useless for real programs — those belong in files.
Common Mistakes
- Forgetting to tick "Add to PATH" on Windows. The single most common setup failure. Your terminal responds with
'python' is not recognizedeven though Python is installed. Fix: re-run the installer, choose Modify, and enable it — no need to uninstall. - Opening a terminal that was already running. A terminal reads PATH when it starts, so a window opened before the install will never see Python. Close it and open a new one.
- Following a Python 2 tutorial. If the code says
raw_input()or bareprint "x", it predates 2020. It will not run. - Installing from the Microsoft Store by accident. That build sandboxes file access and confuses some tooling. Prefer the python.org installer.
- Assuming
pythonandpython3are the same. On macOS and many Linux systems they are different binaries pointing at different versions.
Best Practices
- Use the official installer or your system package manager. Both are signed and keep Python on a normal upgrade path.
- Learn whether your machine wants
pythonorpython3and use it consistently. Mixing them is a reliable source of "but I installed that package" confusion. - Never modify or delete the system Python on macOS or Linux. Parts of the OS depend on it.
- Install
pipalongside Python. The official installers bundle it; some Linux distributions split it into a separate package. - Check the version before debugging anything. A surprising share of "this code doesn't work" turns out to be an unexpected interpreter version.
Practice Exercises
- Confirm the Install: Run
python --version(orpython3 --version) and note the exact version. Confirm the major version is 3. - REPL Arithmetic: Open the interactive shell and evaluate
7 / 2, then7 // 2, then7 % 2. Note how the three results differ, then exit withexit(). - Locate the Interpreter: Run
where pythonon Windows orwhich python3on macOS/Linux to see exactly which file runs when you type the command.