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.
python --version
python3 --versionIf 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.
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
- Open your web browser and go to python.org, then open the Downloads section.
- Download the latest Python 3 installer for Windows.
- Run the installer. On the first screen, tick the box Add Python to PATH. This one step prevents most Windows problems.
- Click Install Now and wait for it to finish.
- Open a new Command Prompt window and type
python --versionto 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:
brew install pythonInstall 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:
sudo apt update
sudo apt install python3 python3-pip python3-venvOn 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.
name = 'Python'
print('Hello from', name)Now open a terminal in the folder that contains the file and run it. Use python on Windows and python3 on macOS and Linux.
python hello.py
python3 hello.pyYou 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.
>>> 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.
import sys
print(sys.version_info.major >= 3)
print(type(sys.version_info.minor))Common installation problems
| Problem | Likely cause | What to do |
|---|---|---|
| 'python' is not recognized (Windows) | Python was not added to PATH | Run the installer again and tick Add Python to PATH, or use py |
| Command not found (Linux, macOS) | You typed python but only python3 exists | Use python3 |
| Old version shows up | Another older Python comes first in PATH | Run python3 --version or check your PATH settings |
| Permission denied on Linux | You tried to install system-wide without rights | Use 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.