Skip to content

Module 1 · Introduction to Python — topic 8 of 14

Installing Python

Step-by-step installation of Python 3 on Windows, macOS and Linux, how to check the installation from a terminal, and how to fix the most common setup problems.

Beginner 15 min read·Lesson 8 of 306 in Python Programming

Learning objectives

  • Install Python 3 on your operating system
  • Verify the installation from a terminal
  • Fix the ‘python is not recognised’ problem

Definition

Step-by-step installation of Python 3 on Windows, macOS and Linux, how to check the installation from a terminal, and how to fix the most common setup problems.

Introduction

Before you can run Python files on your own computer you need the Python interpreter installed. The official, free installer is available from python.org for Windows and macOS, and most Linux systems already include Python 3.

Installation takes a few minutes. The only step that commonly goes wrong is the PATH setting on Windows, which this lesson explains carefully.

Why it matters

Running code locally lets you work offline, save your programs as files and build the projects in this course. The browser examples on this site are useful for reading, but real programs live on your computer.

Detailed explanation

Windows: download the latest Python 3 installer from python.org/downloads. On the first screen tick “Add python.exe to PATH”, then choose Install Now. PATH is the list of folders Windows searches for programs; adding Python lets you type python in any terminal.

macOS: download the macOS installer from python.org and run it. Afterwards use the python3 command in Terminal (the plain python command may not exist).

Linux: most distributions include Python 3. Check with python3 --version. If it is missing, install it with your package manager, for example sudo apt install python3 python3-venv on Ubuntu.

Verify: open a new terminal window (Command Prompt or PowerShell on Windows) and type python --version or python3 --version. You should see something like Python 3.13.1.

Opened the terminal before installing?

Close it and open a new one. Terminals read PATH only when they start.

Syntax

Terminal
python --version
python3 --version
py --version
  • python --version works on Windows (and on systems where python means Python 3).
  • python3 --version is the usual command on macOS and Linux.
  • py --version uses the Windows Python launcher, which is installed with Python.

Code examples

Confirming Python from inside Python

Python
import sys
print("Python", sys.version_info.major)
Output
Python 3

Where is the interpreter?

Python
import sys
print(sys.executable.endswith(("python", "python.exe", "python3")) or len(sys.executable) > 0)
Output
True

sys.executable holds the full path of the running interpreter, useful when you suspect two Pythons are installed.

More examples

A setup check script

Python
import platform
import sys
version = sys.version_info
ok = version >= (3, 10)
print("Operating system detected:", bool(platform.system()))
print("Python 3.10 or newer:", ok)
print("Ready for the course" if ok else "Please upgrade Python")
Output
Operating system detected: True
Python 3.10 or newer: True
Ready for the course

Step-by-step explanation

  • platform.system() returns the operating system name, such as Windows, Darwin or Linux; bool() turns any non-empty name into True.
  • sys.version_info can be compared with a tuple such as (3, 10).
  • ok is True when the version is 3.10 or newer, which every lesson in this course supports.
  • The last line prints one message or the other using a conditional expression.

Expected output

Running “A setup check script” prints exactly:

TextOutput
Operating system detected: True
Python 3.10 or newer: True
Ready for the course

Practical applications

  • Development teams document the required Python version in the project README.
  • Continuous-integration servers install a specific Python version before running tests.
  • IT departments install Python on lab computers with the PATH option enabled for students.

Best practices

  • Install the latest stable Python 3 version from python.org.
  • Avoid installing several versions unless a project requires it.
  • Always check the version in a fresh terminal after installing.

Common mistakes

‘python’ is not recognised as a command

Avoid

Installing on Windows without ticking “Add python.exe to PATH”.

Prefer

Re-run the installer, choose Modify, and enable adding Python to the environment variables; or use the py launcher.

Windows can’t find programs that aren’t on PATH.

Typing python inside the Python shell

Avoid

>>> python --version

Prefer

Type python --version in the terminal, before starting Python.

The >>> prompt means you are already inside Python, which expects Python code, not terminal commands.

Key takeaways

  • Download Python 3 from python.org; Linux usually has it already.
  • On Windows, tick “Add python.exe to PATH”.
  • Check with python --version, python3 --version or py --version.

Try it yourself

  1. 1
    Install Python on your computer and record the exact version number that python --version shows.
  2. 2
    Run the setup check script and confirm it prints “Ready for the course”.

Finished reading? Mark it complete to update your dashboard.

Suggested practice

1 question test this exact topic. Answers and explanations are revealed after you submit.

  • BeginnerWhich command shows the installed Python version?
Practise this topic