Installing Python
Python is a program like any other, and it has to be installed before it can run your code. Until then, the instructions you write in Python are like notes left for a translator who has not arrived yet: perfectly good text, with nobody to read it. This page installs the current version, Python 3.15, from the official source on Windows or a Mac, and proves it worked with a single command.
This is one of the few pages in the book that names specific download pages and installers. Those details change more often than the language does, so if a screen looks slightly different from the description here, trust the official site and the version check at the end.
Where Python Comes From
Python is made by a community of volunteers and published by the Python Software Foundation at python.org. That is the only place this book downloads it from. Sites that offer a Python download with extra bundled software are best avoided, for the same reason you would avoid any installer from an unknown source.
Windows: the Python Install Manager
On Windows, Python is installed through the Python Install Manager, a small tool that installs Python versions and keeps them up to date. You can get it from the Downloads page at python.org, or from the Microsoft Store by searching for Python Install Manager. Both are published by the Python Software Foundation. Install it the way you would install any app.
Then open a new terminal and type python. If no version of Python is installed yet, the Install Manager installs the latest one automatically and starts it. During that first install it may offer to add a folder to your system path, the list of places Windows searches for programs. That step is optional; you can say no, and everything in this book still works.
If you type python and a Python prompt with three greater-than signs appears, type exit() and press Enter to leave it. The next topic explains that prompt properly.
You may see older guides that mention a different Windows installer and a command called py. The older installer is being retired after Python 3.15, and the Install Manager provides the py command too. In this book, on Windows, the command is simply python.
macOS: the python.org Installer
On a Mac, go to the Downloads page at python.org and download the macOS installer for Python 3.15. It is a package file ending in .pkg. Open it and click through the steps; the defaults are right.
On a Mac the command is python3, with the 3 on the end. There is a reason. Your Mac may already have an older copy of Python that came with Apple's developer tools, also called python3. After installing, open a new Terminal window: the new installation is found first, and the version check below tells you which one actually runs.
Linux, Briefly
Most Linux systems already include Python, because parts of the system itself are written in it. Check the version with the command in the next section. If it is older than 3.15, your distribution's package manager can usually provide a newer one. Almost everything in this book also works on Python 3.10 or newer; the few places where 3.15 behaves differently say so. Throughout the book, Linux readers follow the macOS commands.
Proving It Worked
Open a new terminal window and ask Python for its version. On Windows the command is python --version; on a Mac it is python3 --version. Two dashes before the word version, no space between them. The answer should start with Python 3.15.
PS C:\Users\you> python --version Python 3.15.0
you@mac ~ % python3 --version Python 3.15.0
The number after the second dot may be higher by the time you read this. That is fine: it only means a later bug-fix release. What matters is that it starts with 3.15.
If instead you see a message that the command was not found, the terminal could not find a program with that name. On a Mac the message reads: command not found, followed by the name you typed. The usual cause is simple: the terminal window was already open before the installation finished, and it does not know about the new program yet. Close it, open a new one, and try again. On a Mac, also check that you typed python3 and not python.
you@mac ~ % python --version zsh: command not found: python
- "Python is already on my Mac, so I can skip this." The copy that comes with Apple's tools may be old, or missing entirely. The book assumes 3.15, and the version check tells you what you actually have.
- "python and python3 are different languages." They are the same language. The names differ only in how Python is started on different systems, and from Chapter 9 on the command is
pythoneverywhere. - "Having two versions of Python installed means something is broken." Several versions side by side are normal. The version check tells you which one a command starts.
- A working installation removes the most common reason people give up before writing a single line.
- Knowing how to check which Python runs will save you an afternoon the first time two versions disagree.
Knowledge Check
Where does this book get Python from?
- From python.org, the official site of the Python Software Foundation
- From whichever download site appears first in a web search
- From the web browser, which installs Python the first time it opens
- From a paid edition bought through a software reseller online
Which command starts Python on a Mac, in this book?
- python, without any number after it
- python3, with the number 3 on the end
- py, the short launcher for every system
- the .pkg installer you downloaded
Right after installing, the terminal says the Python command was not found. What is the most likely cause?
- The installation failed and must be repeated from the start
- The internet connection dropped while the command was running
- The terminal was opened before the install finished
- The command only works for the computer's administrator
The version check prints Python 3.15.2. Is that right for this book?
- No, the book needs exactly 3.15.0 and nothing else
- Yes, the last number only counts later bug-fix releases
- No, a higher number means the installation went wrong
- Only if you also install version 3.16 alongside it
You got correct