Table of Contents
Before You Install
To write and run Python programs on your computer, you first need the Python interpreter installed. The steps are slightly different depending on whether you use Windows, macOS, or Linux.
This chapter focuses only on:
- How to check if Python is already installed
- How to install Python on each operating system
- A few important options to select during installation
- How to confirm that the installation worked
We’ll use the official CPython distribution from https://www.python.org.
Step 1: Check if Python Is Already Installed
You might already have Python on your system. Let’s quickly check.
On Windows
- Open Command Prompt:
- Press
Winkey, typecmd, press Enter. - In the black window, type:
python --versionand press Enter.
- Possible results:
- If you see something like:
Python 3.12.1then Python 3 is installed.
- If you see an error like:
'python' is not recognized as an internal or external command...then Python is not installed or not on your PATH.
Also try:
py --version
Some Windows installations use py as the Python launcher.
On macOS
- Open Terminal:
- Press
Cmd + Space, typeTerminal, press Enter. - Type:
python3 --versionand press Enter.
- If you see:
Python 3.x.xthen Python 3 is installed.
If it says command not found or only shows Python 2 (e.g. Python 2.7.x for python), you still need to install a recent Python 3.
On Linux
- Open your terminal.
- Type:
python3 --versionand press Enter.
- If you see
Python 3.x.x, you already have Python 3. - If not, you’ll install it using your distribution’s package manager or from python.org.
Step 2: Downloading Python (All Systems)
- Go to the official site:
- Open a browser and visit:
https://www.python.org/downloads/ - The site usually detects your operating system and shows a big button such as:
- “Download Python 3.x.x”
- Make sure the version number starts with
3(e.g.3.12.1), not2.
You’ll now follow the steps specific to your operating system.
Installing Python on Windows
1. Run the Installer
- Download the Windows installer (usually a
.exefile). - Double-click the downloaded file to start the installer.
You’ll see a window titled something like “Install Python 3.x.x”.
2. Important Options on the First Screen
Look carefully at the first installer screen:
- At the bottom, you should see a checkbox:
Add python.exe to PATH
Check this box.
This makes it possible to run Python from the Command Prompt without extra setup.
Next, for beginners, click:
Install Now(recommended)
You do not need “Customize installation” for basic use.
3. Allow Changes and Wait
- If Windows asks whether to allow the app to make changes, click Yes.
- The installer will copy files and set up Python. This may take a minute.
When it finishes, you should see a “Setup was successful” message.
4. Verify the Installation
- Open Command Prompt again.
- Type:
python --versionor
py --version- You should now see something like:
Python 3.12.1If this works, Python is correctly installed and available from the command line.
5. Optional: Check IDLE and Start Menu Entries
After installation, you should find:
- In the Start menu, search for
IDLE(Python’s simple built-in editor). - Also search for
Pythonto see menu entries like: - “Python 3.x”
- “IDLE (Python 3.x 64-bit)”
- “Python Manuals”
These confirm that the installer set up shortcuts correctly.
Installing Python on macOS
You have two common options:
- Use the official Python installer from python.org (recommended for beginners).
- Use a package manager like Homebrew (more common for advanced users).
We’ll focus on the official installer.
1. Run the Official Installer
- From
https://www.python.org/downloads/, download the macOS installer (.pkgfile). - Open the downloaded
.pkgfile. - A standard macOS installer window opens.
2. Go Through the Installer Steps
- Click Continue through the introduction and license screens.
- Accept the license if you agree.
- Click Install to install for all users (or just your account, depending on options).
- Enter your macOS password if prompted.
Wait for the installation to complete. You should see a “The installation was successful” message.
3. Verify the Installation in Terminal
- Open Terminal (
Cmd + Space, typeTerminal). - Type:
python3 --version- You should see:
Python 3.x.xIf that works, Python 3 is installed.
On macOS, you’ll usually use python3 and pip3 instead of python and pip.
4. Check the Installed Applications
The official installer usually adds:
- A folder under Applications called
Python 3.x - This may include:
- IDLE
- Python Launcher
- Documentation
You can open IDLE from there if you want a simple place to type Python code.
Installing Python on Linux
Many Linux distributions already include Python 3, but sometimes it’s an older version. The way you install or update Python depends on your distribution.
Below are common instructions for major families. Always use python3 (not python) when in doubt.
1. Check Existing Python 3
In your terminal:
python3 --version- If this shows
Python 3.x.x, you may already be fine for beginner work. - If it’s missing or very old, install/update using your package manager.
2. Debian / Ubuntu / Linux Mint (APT)
Use the apt package manager.
First, update package information:
sudo apt updateThen install Python 3 (and often pip):
sudo apt install python3 python3-pipVerify:
python3 --version3. Fedora (DNF)
Use the dnf package manager:
sudo dnf install python3Verify:
python3 --version4. openSUSE (Zypper)
Use zypper:
sudo zypper install python3Verify:
python3 --version5. Arch / Manjaro (pacman)
Arch-based systems often have up-to-date Python in the repos:
sudo pacman -S pythonVerify:
python --version
On some Arch systems, python already points to Python 3.
6. Using the Official Python Installer on Linux
Advanced users may choose to compile Python from source downloaded from python.org, but for beginners, using your distribution’s package manager is usually easier and less error-prone.
Common Installation Issues and Quick Checks
“Command Not Found” or “Not Recognized”
If you see errors like:
- Windows:
'python' is not recognized as an internal or external command...- macOS/Linux:
command not found: python3Check:
- Did you actually install Python 3?
- On Windows, did you check “Add python.exe to PATH” during installation?
- On macOS/Linux, are you using
python3instead ofpython?
On Windows, if you forgot the PATH option, you can:
- Re-run the installer and choose “Modify”, then make sure the PATH option is selected, or
- Reinstall and this time check “Add python.exe to PATH”.
Multiple Python Versions
You might have both Python 2 and Python 3 installed.
- On Windows,
pythonusually runs Python 3 (with recent installers). - On macOS and Linux,
pythonmay be Python 2, so usepython3.
Always explicitly use:
python3in this course unless instructions say otherwise.
Final Verification Checklist
After following the steps for your operating system, you should be able to:
- Open a terminal or command prompt.
- Type one of these (depending on your OS):
- Windows:
python --versionor
py --version- macOS/Linux:
python3 --version- See a response like:
Python 3.x.xIf you get that, Python is correctly installed and ready to use in the next chapters.