Home » Wiki » How to Install Python on Windows, macOS, and Linux

How to Install Python on Windows, macOS, and Linux

by | SSL Certificate

Install Python on Windows, macOS, and Linux

A Basic Overview of Python

Python stands out as a favored and adaptable programming language that’s well suited for beginners, in the field today. Its applications range from command line scripts and task automation, to web development and scientific projects.

Python is source. Can be used on popular operating systems such, as Windows, macOS and Linux. With its accessibility, libraries and ease of understanding it serves as a great choice for beginners, in programming and individuals interested in data science to get started with.

This detailed guide will cover the installation of Python, on Windows as macOS and Linux systems. The great thing is that Python can be installed effortlessly on all types of operating systems by following steps, through an installer software package manager provided by the system itself.

Key Takeaways

  • Python can be installed on Windows, macOS, and Linux operating systems. The installation process is straightforward on all three platforms.
  • On Windows, download the Python installer (.exe file) from the official website and run it. During installation, make sure to check the “Add Python to PATH” box.
  • On macOS, Python comes pre-installed, but it’s an older version. To get the latest Python, use Homebrew or download the pkg installer from the Python website.
  • On Linux, use the native package manager like apt, yum, pacman, etc., to install Python and pip. For example, on Ubuntu and Debian, run sudo apt install python3.
  • After installation, verify that Python is installed properly by running the Python—-version on the command line. The pip package manager is also installed with Python.
  • Python virtual environments help manage Python versions and package dependencies for different projects. The venv module on Python 3 creates virtual environments.
  • Set the PATH environment variable properly so you can easily run Python and pip commands from any directory. On Windows, enable the option during Python installation. On Linux/macOS, add Python paths to the PATH variable.

Prerequisites before Installing Python on Windows, macOS, and Linux

Before we delve into platform-specific installation instructions, let’s go over some prerequisites:

  • Make sure you have admin privileges on the computer to install software.
  • Know whether you want to install Python 2 or Python 3. Python 3.x is recommended as Python 2 has reached end-of-life.
  • Decide whether to install the 32-bit or 64-bit version of Python for your system. Modern computers are typically 64-bit.
  • Download the Python installer or package for your operating system from the downloads page of python.org.
  • Optionally, also download pip to install additional Python packages later easily.

A Step-by-Step Guide to Install Python on Windows

Windows does not come with Python pre-installed, so you will need to download the official Python installer and run it manually.

Here are the steps:

  • Download the latest Python 3.x installer for Windows from python.org. It will be in EXE format.
  • Before running the installer, open Command Prompt/PowerShell and check if Python is already installed by running:
python --version
  • If it returns a version, you already have Python and can skip the installation steps.
  • Run the downloaded .exe installer by double-clicking on it.
  • You should see the Python installer wizard. Click ‘Install Now’.
  • By default, Python will be installed to C:\Users\YourUsername\AppData\Local\Programs\Python\Python310. You can change this if needed.
  • Important – On the first installer screen, check the box to Add Python 3.x to PATH. This will ensure Python is accessible from the command line and PowerShell.
  • Click ‘Install’ to begin installing Python. This will also install pip, the standard Python package manager.
  • After installation is complete, click ‘Close.’ A desktop shortcut for IDLE will also be created.

That’s it! Python is now installed and ready to use on your Windows PC.

Let’s verify the installation was successful from the command line:

  • Open Command Prompt/PowerShell, type Python –version, and hit Enter.
  • You should see the newly installed Python version printed, e.g., Python 3.9.1.
  • Type pip –version and hit Enter to check if pip got installed too.

Congratulations, you have installed the latest Python release on your Windows system! Python executables and scripts can now be directly invoked from the command line.

Next, let’s see how to install Python on macOS.

A Step-by-Step Guide to Install Python on macOS

macOS and OS X come with Python 2.x pre-installed by default. However, Python 2 has reached end-of-life and is no longer supported. To develop applications with Python, we need to install Python 3 manually on macOS.

There are a few popular methods to install Python 3 on macOS:

  • Using the Homebrew package manager
  • Downloading and running the Python installer pkg file
  • Building Python from source

The easiest options are Homebrew and the installer pkg. Let’s go through both methods:

Steps to Install Python via Homebrew

Homebrew is a must-have package manager for macOS that makes installing open-source software simple.

Here are the steps to use Homebrew for installing Python 3:

  • First, install Homebrew if you don’t have it already. Open Terminal and run:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
  • Next, update Homebrew’s package database so it has info on the latest package versions:
brew update
  • Now, install Python 3 by running:
brew install python
  • This will install the latest Python 3.x version (which is Python 3.9 as of this writing).
  • To verify Python is installed, run python3 –version in Terminal. You should see the new Python 3.x version printed.
  • Homebrew will also install pip for you. Check it with pip3 –version.

That’s it! With just a few Terminal commands, you have installed the latest Python release using Homebrew. Python and pip will work from the command line and with apps like IDLE.

Let’s also see how to install Python using the installer method next.

Steps to Install Python via the Installer Package

You can also download the Python installer pkg file from the official website and run it on macOS.

Here is how:

  • Download the macOS installer file from python.org. Get the latest Python 3 release.
  • Double click the downloaded python-x.x.x-macos10.9.pkg file. This will launch the installer.
  • Follow the installation prompts to install Python 3 to the default location of /Library/Frameworks/Python.framework/Versions/.
  • During installation, enable the option to Add Python to PATH so it is accessible from the Terminal.
  • The installer will also install pip for managing packages.
  • After installation completes, verify with python3 –version and pip –version in Terminal.

The pkg installer configures Python properly on macOS. Python 3 and pip will now run from Terminal or any IDE/editor you prefer.

This covers the two main installation methods for macOS. Next up, we’ll discuss how to install Python on Linux OS.

A Step-by-Step Guide to Install Python on Linux

Unlike Windows and macOS, Linux distributions come with Python pre-installed. However, the pre-installed version tends to be an older Python 2.x release since many legacy systems still rely on it.

To run the latest Python 3.x on Linux, we need to use the native package manager available in your Linux distro. Common options are:

  • apt: For Debian, Ubuntu, Pop!_OS, Linux Mint
  • yum: For RHEL, CentOS, Fedora, openSUSE
  • dnf: A newer version of yum used in the latest Fedora releases
  • pacman: For Arch Linux and Manjaro
  • apk: For Alpine Linux
  • zypper: For SUSE and openSUSE

These package managers allow installing, updating, and removing software packages on Linux OS. Let’s go through some examples for installing the latest Python 3 release:

On Debian/Ubuntu

Debian and Ubuntu use the apt package manager:

  • Update apt’s package index:
sudo apt update
  • Install Python 3 and pip:
sudo apt install python3 python3-pip
  • Verify with python3 –version and pip3 –version.

The apt commands above will install the latest Python 3 available in the OS repositories along with pip.

On CentOS/RHEL

  • Update yum package index:
sudo yum update
  • Install Python 3:
sudo yum install python3
  • Verify with python3 –version.

This will pull the latest Python 3 release from the yum repositories and install it.

On Fedora

Modern Fedora versions use dnf:

sudo dnf install python3

Then confirm with python3 –version.

On Arch Linux

  • Update the pacman package manager:
sudo pacman -Syu
  • Install Python:
sudo pacman -S python

Pacman will install the latest Python 3 by default. Check it using python3 –version.

And that’s it: you now know how to install Python 3 on most common Linux distributions using the built-in package manager! Package managers make it really easy to keep Python and pip up-to-date on Linux.

Next, let’s look at how to set up virtual environments for Python.

How to Setting Up Python Virtual Environments

Now that you have Python installed, it’s good practice to create isolated virtual environments for your Python projects rather than use system-wide Python.

Virtual environments enable you to have a separate Python setup for each project with its packages, thereby avoiding version conflicts between projects.

Python 3 comes with a built-in venv module to create virtual environments. Let’s see how to use it:

  • Open a new command prompt/terminal and navigate to your project directory. Create a new folder:
mkdir myproject
cd myproject
  • Run the venv module with the virtual environment name:
python3 -m venv myenv
  • This will create a folder called myenv in your project directory containing the virtual Python installation.
  • Activate the virtual environment:
  • On Windows:
myenv\Scripts\activate
  • On macOS/Linux:
source myenv/bin/activate
  • Your command prompt will now indicate the virtual environment in brackets.
  • Install packages like numpy within this virtual environment:
python -m pip install numpy
  • Use deactivate when done working on the project.

The packages installed inside myenv will remain isolated from other projects. For your next project, create a new virtual environment using Python -m venv again.

This enables a clean Python environment for each project!

Next, we’ll look at how to configure the PATH variable properly for accessing Python and pip easily.

How to Setting Up PATH Variable for Python

The PATH environment variable stores directories on the filesystem where executable programs are located. This allows you to run commands and programs from any location without having to specify the full path.

To be able to run Python and pip from any shell/terminal, the PATH variable needs to include the following paths:

  • The folder where the python executable is located is typically C:\PythonXX\ on Windows or /usr/local/bin/ on Linux/macOS.
  • The Scripts/ or bin/ directory inside the Python folder containing pip and other scripts.

The steps for adding a Python directory to PATH are:

On Windows

  • During Python installation on Windows, you can enable the option to Add Python to PATH automatically. This modifies PATH to include Python’s directories.
  • If you missed this step, you can manually add the paths later:
  • Go to Start and search for “Edit the system environment variables.”
  • Click the Environment Variables button.
  • Under System Variables, find the PATH variable and click Edit.
  • Add Python’s installation path like C:\Python39\ and C:\Python39\Scripts\ to PATH. Separate entries with a semicolon.
  • Click OK and close all windows.
  • Open a new terminal and check if Python/pip commands work properly.

On Linux and macOS

  • The PATH variable is stored in shell startup scripts like .bashrc or .zshrc.
  • Open your shell profile file in a text editor. For example:
nano ~/.bashrc
  • Add these lines at the end to add Python directories:
export PATH="/usr/local/bin:/usr/local/lib/python3.8/bin:$PATH"
  • Save and close the file. Restart your terminal or run source ~/.bashrc to reload the profile.
  • Verify you can run python and pip commands now.

This permanently adds Python to the PATH variable on Linux/macOS for all shells!

How to Verify If Python Has Been Set Up Successfully or Not?

After going through the installation steps for your operating system, let’s validate Python has been set up correctly:

  • Open a new Terminal/Command Prompt window and run:
python --version
  • It should print the newly installed Python version.
  • Also, check pip version:
pip --version
  • Try running a simple Python script:
 print("Hello World")
  • Run a pip command to install a module like numpy:
pip install numpy
  • Import and use numpy in a script to verify it is installed correctly.
  • Check that python and pip commands work from any directory.

If all these work fine, you have successfully installed the latest Python release on your Windows, macOS, or Linux machine, and you are ready to start coding in Python.

Final Thoughts

Setting up Python on your computer is an task as you embark on your path to becoming a skilled programmer. Regardless of whether you’re working with Windows or macOS or Linux systems. It is a process, with advantages of having Python readily available.

Python offers a range of applications from automating tasks to developing programs. Its flexibility and user friendly nature make it a top pick, for both novice and seasoned developers alike.

By following the steps laid out in this guidebook you’ll make strides in harnessi​ng Pythons capabilities. Enhancing your coding expertise to reach greater heights.

Priya Mervana

Priya Mervana

Verified Badge Verified Web Security Experts

Priya Mervana is working at SSLInsights.com as a web security expert with over 10 years of experience writing about encryption, SSL certificates, and online privacy. She aims to make complex security topics easily understandable for everyday internet users.