06. Setup
Before writing any Python, three things need to be on the computer:
- The Python interpreter (the program that runs
.pyfiles). - A code editor.
- A terminal for typing commands.
This chapter sets up all three on Windows 10 or 11.
1. Install the Python interpreter
There is more than one way to install Python on Windows. Pick one of the two methods below. If the first fails, try the second.
Method A: winget (recommended)
Windows 10 and 11 ship with winget, a tool that installs
software from the command line. To use it:
Press the Windows key, type
PowerShell, and open it.Type:
winget search Python.PythonA table appears listing packages that match. Look for the row whose Id has the form
Python.Python.3.xwith the highest number, such asPython.Python.3.13. Copy the value in the Id column for that row.Install it with:
winget install --id <paste-the-id-here>For example, if the Id is
Python.Python.3.13, the command iswinget install --id Python.Python.3.13.Close PowerShell and open a new window. This matters: the new window picks up the
PATHchange the installer made.Verify the install:
python --versionYou should see a line that starts with
Python 3.followed by a version number. If you see that, Python is installed. Skip to step 2.
If python --version prints an error containing
The term 'python' is not recognized, the installer did not
add Python to PATH. Use Method B instead. Do the same if it
prints
Python was not found; run without arguments to install from the Microsoft Store:
that message comes from a Windows shortcut, not from Python.
Method B: download from python.org
If winget did not work, install Python manually:
- Go to https://www.python.org/downloads/ and click Download Python install manager. Do not use the standalone installer link below it, which is being phased out.
- Run the downloaded file and click Install.
- Open a new PowerShell window and run
python --version. The first time, the install manager downloads the latest Python, so this can take a few minutes. If it asks whether to add a folder toPATH, answer yes. - You should see the Python version.
If python is still not found, press the Windows
key, open Manage app execution aliases, and
check that the Python (default) alias is on. Then open
a new PowerShell window and try again.
2. Install a code editor
Use Visual Studio Code (VS Code for short). It is free, runs on Windows, and is the same editor most professionals use.
- Open https://code.visualstudio.com and download the installer.
- Run it. On the Select Additional Tasks screen, tick Add to PATH and Register Code as an editor for supported file types.
- Open VS Code once the install finishes.
- Install the Python language extension:
- Click the Extensions icon in the left bar (or press Ctrl + Shift + X).
- Type
pythonin the search box. - Find the extension called Python published by Microsoft (the publisher's name is shown under the title).
- Click Install.
This adds syntax colouring, autocomplete, and inline error hints for
.py files.
3. The terminal
VS Code has a built in terminal. Open it with **Ctrl +
** (the backtick key, usually under Esc`).
This is where you type python some-file.py to run a
script; its output appears in the same terminal.
4. Verify everything works
Open VS Code and create a working folder:
Choose File → Open Folder..., click New Folder, name it
python-work, click Select Folder.Press Ctrl + N to create a new file.
Type:
print("Hello, world!")Save it as
hello.pyinside the folder (Ctrl + S).Open the terminal (Ctrl + `) and type:
python hello.py
You should see:
Hello, world!
If you do, the whole setup is working. Move on to Chapter 7.
How the example code is organised
All exercise files are in the Exercises section of this book — browse them online or download any file to run it locally. To reach it, click the book title at the top of the sidebar, then Exercises.
To get every file at once, download python-101-files.zip,
save it in your python-work folder, and type this in the VS
Code terminal:
Expand-Archive python-101-files.zip -DestinationPath .
Your python-work folder now holds
exercises/ and projects/.
Every chapter with code gets a matching folder under
exercises/, numbered to match the chapter:
Chapter 7's code is in exercises/07/, Chapter 20's is in
exercises/20/, and so on. (Part 1 is all on paper, so the
code begins at Chapter 7.) The mini-projects are separate, in
projects/.
Each chapter's folder holds three kinds of file:
- Example files at the top level, like
exercises/08/01-comment-styles.py. These are the small programs the chapter's Try this boxes ask you to run. - A
homework/folder with a starter file for each homework problem, likeexercises/08/homework/01-annotate.py. - A
homework/solutions/folder with a worked answer for every homework problem. Try the homework yourself first — the answers are there for when you get stuck or want to check your work.
When a chapter says "open
exercises/08/homework/01-annotate.py", find that file in
the Exercises section, download it, and save it in the same path inside
your python-work folder.
What this chapter did not cover
- pygame. The final part of the book covers pygame for making graphical games. For now, everything runs as plain text programs in the terminal.
- Other editors. Others work fine (Notepad++, Sublime Text, IDLE), but the book assumes VS Code from here on. With a different editor the keyboard shortcuts change, but the code is identical.