Guides & Roadmaps

How to Install Python on Windows, macOS and Linux

Before you can run Python programs on your own computer, you need to install Python. The steps are simple, but they are a little different on Windows, macOS and Linux. This guide shows each system, how to check that the install worked, and how to run your first script.

The official place to download Python is python.org. Always get Python from there or from your operating system's own package manager, so you know the files are safe.

Check if Python is already installed

Many computers already have Python. Open a terminal (on Windows, use Command Prompt or PowerShell) and type one of these commands. Which one works depends on your system.

Check the version
python --version
python3 --version

If you see a message like Python 3.x.y, Python is installed, and the numbers show your version. If you see an error such as "command not found" or "Python was not found", you need to install it. This site uses Python 3, so make sure your version starts with 3. A recent Python 3 release is best, because some features in later chapters need Python 3.10 or newer.

On macOS and Linux the command is usually python3. On Windows it is usually python. A plain python on an old Linux system may point to the obsolete Python 2, so prefer python3 there.

Install Python on Windows

  1. Open your web browser and go to python.org, then open the Downloads section.
  2. Download the latest Python 3 installer for Windows.
  3. Run the installer. On the first screen, tick the box Add Python to PATH. This one step prevents most Windows problems.
  4. Click Install Now and wait for it to finish.
  5. Open a new Command Prompt window and type python --version to check.

Windows also has a launcher called py. If python does not work but py --version does, you can use py in place of python for all the commands in this guide.

Install Python on macOS

The easiest way is the official installer from python.org. Download the macOS installer, open the file and follow the steps. After it finishes, open Terminal and run python3 --version.

If you already use Homebrew, you can install Python from the terminal instead:

Install with Homebrew
brew install python

Install Python on Linux

Most Linux distributions include Python 3. If yours does not, use the package manager of your distribution. On Debian and Ubuntu the commands are:

Debian or Ubuntu
sudo apt update
sudo apt install python3 python3-pip python3-venv

On Fedora you can use sudo dnf install python3. After the install, check with python3 --version.

Which editor should I use?

You can write Python in any plain text editor. Beginners often like Visual Studio Code or the IDLE editor that comes with Python on Windows and macOS. Choose one and stay with it for a while. The editor matters much less than the habit of writing code every day.

Run your first script

A Python script is a text file that ends in .py. Create a file named hello.py with this content. You can use any folder, for example a new folder called python-practice.

hello.py
name = 'Python'
print('Hello from', name)
Hello from Python

Now open a terminal in the folder that contains the file and run it. Use python on Windows and python3 on macOS and Linux.

Run the script
python hello.py
python3 hello.py

You should see the greeting printed on the screen. If so, congratulations: your setup works.

Use the interactive prompt

Typing python or python3 alone starts the interactive prompt, also called the REPL. You type one line, press Enter and see the result at once. It is perfect for trying small ideas. To leave it, type exit() and press Enter.

Interactive prompt
>>> 2 + 3
5
>>> 'py' * 3
'pypypy'
>>> exit()

Check from inside Python

You can also ask Python itself which version is running. This is useful when you have more than one version installed.

Print the running version
import sys
print(sys.version_info.major >= 3)
print(type(sys.version_info.minor))
True <class 'int'>

Common installation problems

ProblemLikely causeWhat to do
'python' is not recognized (Windows)Python was not added to PATHRun the installer again and tick Add Python to PATH, or use py
Command not found (Linux, macOS)You typed python but only python3 existsUse python3
Old version shows upAnother older Python comes first in PATHRun python3 --version or check your PATH settings
Permission denied on LinuxYou tried to install system-wide without rightsUse sudo for the package manager, or use a virtual environment

What to do next

Once Python runs, your next step is to learn about virtual environments, which keep the packages of each project separate. Read the guide on virtual environments and pip on this site. Then open the first chapter in /tutorials and start typing the examples yourself. If something does not work, read the error message slowly; the guide on reading Python error messages will help.

More guides

« All guides