These are the setup notes from the book, kept current here. If an installer screen has changed since your copy was printed, this page is the version to follow.
Three things have to be in place before any program in this book will run: Python 3 itself, an editor to write code in, and a terminal to run it from. It is all free, and the setup takes about fifteen minutes. Work through it once and you will not have to think about it again.
Install Python 3
Windows does not come with Python. The copy included with macOS is there for the system’s own use rather than yours. Install the current release from the official site.
- Open
python.org/downloadsin your browser. The page offers the latest Python 3 release for the system you are on. - Download the installer and run it.
- On Windows, this is the step that matters: select the checkbox Add
python.exetoPATHon the first installer screen. It is what lets you typepythonin a terminal later. - Click Install Now, or Continue on macOS, and accept the defaults until it finishes.
- Close the installer, and close any terminal window that was already open, since a terminal learns about a new installation only when it starts. On macOS, type
python3rather thanpythonfrom here on.
Now check the result, in a terminal window. If you have never opened one, read Open a Terminal below first, then type this command and press Enter.
Windows Command Prompt:
C:\Users\you> python --version
Python 3.13.2
macOS Terminal:
~ % python3 --version
Python 3.13.2
Your version number will be different, and that is fine. Anything beginning with 3 runs every program in this book. If a message appears instead, When Something Goes Wrong covers it.
Choose an Editor
You also need somewhere to write the code. A word processor will not do, since it saves formatting along with the text. All four editors below are free.
Thonny
Download Thonny from thonny.org and run the installer. It can bring its own copy of Python, which helps if the installation above gave you trouble, and one green Run button, or F5, runs the file you are editing.
IDLE
IDLE arrives with Python itself, so it is already on the machine: look in the Start menu on Windows or the Applications folder on macOS. It is plain, and it runs a saved .py file with F5.
VS Code
Download VS Code from code.visualstudio.com, and install the Python extension it offers you on first use, since that is what gives you the Run button. The habit that matters here is opening a folder rather than a single file: File, then Open Folder, on the folder where you keep this book’s programs.
Notepad++
Notepad++, from notepad-plus-plus.org, is a Windows-only plain-text editor with no Run button, so you run your programs from a terminal. Watch the save dialog: set Save as type to All types and type the full name, hello.py, or you get hello.py.txt, which Python will not run.
| Editor | Best for | Where to get it |
|---|---|---|
| Thonny | Your first weeks. One Run button, nothing to configure. | thonny.org |
| IDLE | Starting immediately. It is already installed with Python. | comes with Python |
| VS Code | Everything after that. The tool you are likely to keep. | code.visualstudio.com |
| Notepad++ | Windows users who want a plain editor and a terminal. | notepad-plus-plus.org |
I recommend Thonny for the first week. There is almost nothing in it to get lost in, and that is the point while you are still learning what a program looks like. Move to VS Code once running a file feels routine. Nothing in this book depends on which one you pick.
Open a Terminal
A terminal is a plain window where you type one command, press Enter, and read what the computer prints back. It is not a programming language. It is the place where you start programs.
On Windows, press the Windows key, type cmd, and open Command Prompt. Newer versions of Windows open it inside Windows Terminal, and PowerShell works the same way here. On macOS, open Terminal from the Utilities folder inside Applications.
The line it shows you is the prompt, and it names the folder you are standing in. Move to another folder with cd, short for change directory.
Windows Command Prompt:
C:\Users\you> cd C:\pythonbook
C:\pythonbook>
macOS Terminal:
~ % cd ~/pythonbook
pythonbook %
One warning. If you run python with no file name after it, you land in Python’s interactive prompt, where every line begins with >>>. Type exit() and press Enter to leave it. The programs in this book are files, and you run them the way the next section shows.
Write and Run Your First Program
- Make one folder for your work: C:\pythonbook on Windows, or a folder named pythonbook in your home folder on macOS. Every program from this book goes in it.
- In your editor, choose File, then New. Type the line
print("Hello, World!")and save it into that folder ashello.py. Type the .py ending yourself, since it is part of the name. - In Thonny or IDLE, press F5. In VS Code, click the Run button. The output appears in the panel at the bottom of the window.
- To run the same file from a terminal, move into the folder with cd, as shown above, then run the file by name.
Windows Command Prompt:
C:\pythonbook> python hello.py
Hello, World!
macOS Terminal:
pythonbook % python3 hello.py
Hello, World!
The first line of each pair is what you type. The line under it, with no prompt in front of it, is your program’s output. Every RUN step in this book means exactly that: save the file, run it, and compare the output with your prediction. Chapter 1 starts from here, with the same file.
When Something Goes Wrong
| What you see | What it means |
|---|---|
'python' is not recognized as an internal or external command |
Windows cannot find Python, almost always because Add python.exe to PATH was not selected during installation. Run the installer again, choose Modify, select that checkbox, and open a new Command Prompt. A Microsoft Store page opening instead means the same thing. |
python: can't open file '...\hello.py': [Errno 2] No such file or directory |
You are running the command in the wrong folder. Python looks for the file where you are standing, not where you saved it. Use cd to move into the folder that holds hello.py, then run it again. |
| The same message, although the file is plainly there | The file was saved as hello.py.txt. Windows hides known file endings, and Notepad adds .txt unless told otherwise. Save again with Save as type set to All types, and turn on File name extensions in the View menu of File Explorer. |
One more thing worth knowing before you need it. Some programs never stop on their own, and you will meet one on purpose in Chapter 5. Press Ctrl+C in the terminal to interrupt a running program, or click Stop in Thonny or IDLE.
The Companion Website
The files that go with this book are free at tprmway.com/python: printable cheat sheets, fifty extra practice questions, starter files for the four projects, and any corrections made after printing. Nothing in the book depends on them. Tools change faster than languages. If a program name or download address in this section has moved on by the time you read it, the website keeps a current version of these setup notes.