This guide provides detailed instructions for installing Python on Windows, macOS, and Linux operating systems. It covers multiple installation methods, troubleshooting tips, and best practices for each platform.
Windows Installation
Method 1: Using the Official Installer
- Visit the official Python website: https://www.python.org/downloads/windows/
- Click on the latest Python 3 release (e.g., “Python 3.10.x”)
- Scroll down to the “Files” section and download the appropriate installer:
- For 64-bit: “Windows installer (64-bit)
- For 32-bit: “Windows installer (32-bit)
Method 2: Using Microsoft Store
- Once downloaded, run the installer
- Important: Check the box that says “Add Python 3.x to PATH”
- Click “Install Now” for a standard installation, or “Customize installation” for more options
- If you choose “Customize installation”:
- In “Optional Features”, select all options
- In “Advanced Options”, check “Install for all users” and “Add Python to environment variables”
- Click “Install” and wait for the process to complete
Method 2: Using Microsoft Store
- Open the Microsoft Store on your Windows 10/11 machine
- Search for “Python”
- Select the latest version of Python 3
- Click “Get” or “Install”
- Wait for the installation to complete
Method 3: Using Chocolatey Package Manager
- First, install Chocolatey if you haven’t already:
- Open PowerShell as Administrator
- Run the following command:
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
ShellSession- Once Chocolatey is installed, run:
choco install python
ShellSession- Follow the prompts to complete the installation
Post-Installation Steps for Windows
- Open Command Prompt or PowerShell
- Verify Python installation by typing:
python --version
ShellSession- Verify pip (Python package manager) installation:
pip --version
ShellSession- Update pip to the latest version:
python -m pip install --upgrade pip
ShellSessionmacOS Installation
Method 1: Using the Official Installer
- Visit https://www.python.org/downloads/mac-osx/
- Download the latest Python 3 release for macOS
- Open the downloaded .pkg file
- Follow the installation wizard, accepting the license agreement and choosing the installation location
- If prompted, enter your system password to allow the installer to make changes
Method 2: Using Homebrew
- Open Terminal
- Install Homebrew if you haven’t already:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
ShellSession- Once Homebrew is installed, run:
brew install python
ShellSessionPost-Installation Steps for macOS
- Open Terminal
- Verify Python installation:
python3 --version
ShellSession- Verify pip installation:
pip3 --version
ShellSession- Update pip:
pip3 install --upgrade pip
ShellSessionLinux Installation
There is a good chance that python is already installed in your Linux distribution but still here is the guide below to install/update python in your Linux machine
Ubuntu/Debian
- Open Terminal
- Update package lists:
sudo apt update
ShellSession- Install Python 3:
sudo apt install python3 python3-pip
ShellSessionFedora
- Open Terminal
- Install Python 3:
sudo dnf install python3 python3-pip
ShellSessionCentOS/RHEL
- Open Terminal
- Enable EPEL repository:
sudo yum install epel-release
ShellSession- Install Python 3:
sudo yum install python3 python3-pip
ShellSessionVerifying the Installation
Regardless of your operating system, you can verify your Python installation by following these steps:
- Open a terminal or command prompt
- Run the following commands:
python --version # or python3 --version on some systems
pip --version # or pip3 --version on some systems
ShellSession- Start the Python interactive shell:
python # or python3 on some systems
ShellSession- In the Python shell, try running a simple command:
print("Hello, World!")
Python- Exit the Python shell:
exit() # or ctrl + d
ShellSessionBonus Content | Setting Up a Virtual Environment
Virtual environments are isolated Python environments that allow you to manage project-specific dependencies. Here’s how to set them up:
- Install virtualenv (if not already installed):
pip install virtualenv
ShellSession- Create a new virtual environment:
python -m venv myenv
ShellSession- Activate the virtual environment:
- On Windows:
- On Windows:
myenv\Scripts\activate
ShellSession- Activate the virtual enviroment
- On macOS and Linux:
source myenv/bin/activate
ShellSession- To deactivate the virtual environment, simply run:
deactivate
ShellSession