Set up your Python lab ๐ง
Ten minutes, once. Pick your operating system below. Every step says what to type, what you should see, and what to do when you see something else instead.
Windows
- Download the installer. Go to python.org/downloads and press the big yellow button. It detects Windows automatically.
- Tick the box. This is the whole lesson. On the first installer
screen there is a checkbox at the bottom: "Add python.exe to PATH".
Tick it. If you miss it, the terminal will not find Python and you will spend an hour
confused. Then press "Install Now".
๐ชค Ninety percent of Windows setup pain is that unticked box. If you already installed without it, re-run the installer, choose "Modify", and add it.
- Open PowerShell. Press Start, type
powershell, press Enter. - Check it worked.
Any 3.11 or newer is fine.PS C:\Users\you> python --version Python 3.13.5 - Check pip too. pip installs other people's code and comes with
Python.
PS C:\Users\you> pip --version pip 25.0 from C:\... (python 3.13)
Typing python on a fresh Windows sometimes opens the Store. That is a placeholder, not Python. Install from python.org instead: the Store build sandboxes file access in ways that will confuse you later.
macOS
- Do not use the Python that is already there. macOS ships an old Python for its own use. Leave it alone.
- Install a real one. Either download from
python.org/downloads and run the
.pkg, or if you use Homebrew:brew install python@3.13 - Open Terminal. Cmd+Space, type
terminal, Enter. - Check it.
Always$ python3 --version Python 3.13.5python3with the 3, on macOS. - Check pip.
Using$ python3 -m pip --version pip 25.0 from /opt/homebrew/... (python 3.13)python3 -m piprather than barepipguarantees you are installing into the same Python you are running. Make it a habit.
Linux
It is already installed. Check which version:
$ python3 --version
Python 3.12.3
If it is older than 3.11, or pip and venv are missing:
# Debian, Ubuntu, Mint
sudo apt update && sudo apt install python3 python3-pip python3-venv
# Fedora
sudo dnf install python3 python3-pip
# Arch
sudo pacman -S python python-pip
On Linux the system Python belongs to your package manager, and installing things into it with sudo pip can break system tools. Newer distros block it outright with an externally-managed-environment error. That error is protecting you. Use a virtual environment (Lesson 26); it is two commands and it makes the problem disappear forever.
An editor that helps you
Take VS Code unless you have a reason not to. It is free, runs everywhere, and every tutorial on earth assumes it.
- Install VS Code from the link above.
- Install the Python extension. Open the Extensions panel (the blocks icon in the sidebar), search "Python", install the one published by Microsoft. You get colouring, error squiggles, autocomplete and a Run button.
- Open a folder, not a file. File, Open Folder, choose your
python-schoolfolder. This one habit prevents a surprising amount of confusion later. - Pick your interpreter. Press Ctrl+Shift+P (Cmd+Shift+P on Mac), type "Python: Select Interpreter", choose the 3.13 you just installed.
- Turn on format-on-save once you reach Lesson 30. Settings, search "format on save", tick it. Never argue about spacing again.
Ctrl+S save. Ctrl+/ comment out the selected lines. Ctrl+Shift+P the command palette, which can do everything. Ctrl+` opens a terminal inside the editor, already standing in your project folder. On a Mac, Cmd instead of Ctrl.
When it breaks
| What you see | What it means | What to do |
|---|---|---|
command not found: python3'python' is not recognized | The shell cannot find Python | Windows: reinstall with 'Add to PATH' ticked. All: close and reopen the terminal after installing |
can't open file 'hello.py' | You are not in the folder that holds the file | Run ls (or dir) and look. cd to the right folder |
SyntaxError: invalid syntax | A typo. Very often a missing bracket or quote on the line ABOVE the one named | Read the line number, then look one line up. Lesson 10 covers this properly |
IndentationError | Your spacing is inconsistent | Use four spaces per level, never tabs. In VS Code: 'Convert Indentation to Spaces' |
ModuleNotFoundError: No module named 'x' | That package is not installed in the Python you are running | python3 -m pip install x, and see Lesson 26 on virtual environments |
externally-managed-environment | Linux is protecting its system Python | Make a virtual environment: python3 -m venv .venv then activate it |
| Two Pythons, wrong one runs | PATH order | which python3 (macOS/Linux) or where python (Windows) shows which one wins |
The universal check
When anything is confusing, ask Python itself which Python is talking:
import sys
print(sys.version)
print(sys.executable)
That prints the exact version and the exact file being run. Nine times out of ten, "it works in my editor but not my terminal" is those two lines disagreeing.
Prove the lab works
Make a file called hello.py, put this in it, and run
python3 hello.py:
import sys
print("Python is installed and working.")
print(f"Version: {sys.version.split()[0]}")
print("Lab status: operational. Go and learn something.")
Three lines of output means you are done. Go to Level 1.