How to Install Python on Linux, macOS, and Windows
🏷️ Setting Up Your Python Environment / Installing Python
Before you can start writing and running Python code, you need to have Python installed on your machine. This guide walks you through the installation process on the three major operating systems: Linux, macOS, and Windows. By the end, you'll have Python ready to go, no matter which platform you're using.
🖥️ Checking if Python is Already Installed
Many systems come with Python pre-installed. Before installing, it's a good idea to check what's already available.
- Open your terminal (Linux/macOS) or command prompt (Windows).
- Type python --version or python3 --version and press Enter.
- If you see a version number (e.g., Python 3.10.5), Python is already installed.
- If you see an error message like "command not found," you'll need to install Python.
🐧 Installing Python on Linux
Linux distributions often include Python, but it may be an older version. Here's how to install or update it.
Using the Package Manager
- Ubuntu/Debian-based systems: Open a terminal and run sudo apt update followed by sudo apt install python3.
- Fedora/RHEL-based systems: Use sudo dnf install python3.
- Arch Linux: Use sudo pacman -S python.
Verifying the Installation
- After installation, type python3 --version to confirm the installed version.
- You can also check that pip (Python's package installer) is available by typing pip3 --version.
🍎 Installing Python on macOS
macOS comes with Python 2.x pre-installed on older versions, but Python 3 is recommended for all new projects.
Option 1: Using the Official Installer
- Visit the official Python website at python.org.
- Download the latest Python 3 installer for macOS.
- Open the downloaded .pkg file and follow the installation wizard.
- Once installed, open Terminal and type python3 --version to verify.
Option 2: Using Homebrew
- If you have Homebrew installed, open a terminal and run brew install python.
- Homebrew will install the latest Python 3 and set it up automatically.
- Verify with python3 --version.
🪟 Installing Python on Windows
Windows does not come with Python pre-installed, but installation is straightforward.
Using the Official Installer
- Go to python.org and download the latest Python 3 installer for Windows.
- Run the installer and check the box that says "Add Python to PATH" at the bottom of the setup window.
- Click Install Now and wait for the installation to finish.
- After installation, open Command Prompt and type python --version to confirm.
Using the Microsoft Store
- Open the Microsoft Store from your Start menu.
- Search for Python and select the latest version (e.g., Python 3.12).
- Click Get or Install and wait for the process to complete.
- Verify by typing python --version in Command Prompt.
🔄 Comparison of Installation Methods
| Operating System | Recommended Method | Ease of Use | Package Manager Support |
|---|---|---|---|
| Linux | Package manager (apt, dnf, pacman) | Easy | Yes |
| macOS | Official installer or Homebrew | Easy | Yes (via Homebrew) |
| Windows | Official installer with PATH option | Very Easy | No (but pip works) |
🛠️ Verifying Your Installation
Once Python is installed, run these checks to ensure everything is working.
- Check Python version: Type python --version (Windows) or python3 --version (Linux/macOS).
- Check pip version: Type pip --version or pip3 --version.
- Run a simple test: Type python -c "print('Hello, Python!')" and you should see the message printed.
⚙️ What is pip and Why Do You Need It?
pip is Python's package installer. It allows you to install additional libraries and tools that extend Python's functionality.
- pip comes bundled with Python 3.4 and later versions.
- To install a package, use pip install package_name.
- To see what packages are already installed, use pip list.
- To update pip itself, use pip install --upgrade pip.
🕵️ Troubleshooting Common Issues
If something doesn't work after installation, here are a few things to check.
- "Python is not recognized" on Windows: You likely forgot to check "Add Python to PATH" during installation. Re-run the installer and make sure that box is checked.
- Multiple Python versions: If you have both Python 2 and Python 3, use python3 on Linux/macOS or py on Windows to specify Python 3.
- Permission errors on Linux/macOS: Use sudo before your install command if you get permission denied errors.
- Firewall or proxy blocking downloads: If you're behind a corporate firewall, you may need to configure proxy settings or use an offline installer.
✅ Summary
- Python can be installed on Linux, macOS, and Windows using simple methods.
- Always verify your installation by checking the version and testing a basic command.
- pip is automatically included and is essential for managing Python packages.
- If you run into issues, check your PATH settings and permissions first.
With Python installed, you're now ready to start writing and running your first scripts.
This guide shows you how to install Python on the three major operating systems using command-line and installer methods.
💻 Example 1: Check if Python is already installed on your system
This example verifies whether Python is already present on your machine before installing.
# Open your terminal (Linux/macOS) or Command Prompt (Windows)
# Type the following command and press Enter:
python --version
📤 Output: Python 3.12.0 (or similar version number, or an error if not installed)
💻 Example 2: Install Python on Linux using the package manager
This example installs Python on Ubuntu/Debian-based Linux distributions using apt.
# Open terminal and run these commands one at a time:
sudo apt update
sudo apt install python3
python3 --version
📤 Output: Python 3.12.0
💻 Example 3: Install Python on macOS using Homebrew
This example installs Python on macOS using the Homebrew package manager.
# Open Terminal and run these commands one at a time:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
brew install python
python3 --version
📤 Output: Python 3.12.0
💻 Example 4: Install Python on Windows using the official installer
This example downloads and installs Python on Windows using the executable installer from python.org.
# Step 1: Open a web browser and go to:
# https://www.python.org/downloads/
# Step 2: Click the "Download Python 3.x.x" button
# Step 3: Run the downloaded installer file
# Step 4: Check the box "Add Python to PATH"
# Step 5: Click "Install Now"
# Step 6: Open Command Prompt and verify:
python --version
📤 Output: Python 3.12.0
💻 Example 5: Verify Python installation with a simple script
This example confirms Python is working by running a one-line program.
# Create a new file called hello.py with this content:
print("Python is installed and working!")
# Then run it from the terminal:
python hello.py
📤 Output: Python is installed and working!
📊 Comparison Table: Python Installation Methods
| Operating System | Method | Command/Steps | Verification Command |
|---|---|---|---|
| Linux (Ubuntu/Debian) | Package Manager (apt) | sudo apt install python3 |
python3 --version |
| macOS | Homebrew | brew install python |
python3 --version |
| Windows | Official Installer | Download from python.org, run installer | python --version |
| Any OS | Check existing installation | python --version or python3 --version |
Shows version or error |
| Any OS | Run test script | Create hello.py with print("...") |
python hello.py |
Before you can start writing and running Python code, you need to have Python installed on your machine. This guide walks you through the installation process on the three major operating systems: Linux, macOS, and Windows. By the end, you'll have Python ready to go, no matter which platform you're using.
🖥️ Checking if Python is Already Installed
Many systems come with Python pre-installed. Before installing, it's a good idea to check what's already available.
- Open your terminal (Linux/macOS) or command prompt (Windows).
- Type python --version or python3 --version and press Enter.
- If you see a version number (e.g., Python 3.10.5), Python is already installed.
- If you see an error message like "command not found," you'll need to install Python.
🐧 Installing Python on Linux
Linux distributions often include Python, but it may be an older version. Here's how to install or update it.
Using the Package Manager
- Ubuntu/Debian-based systems: Open a terminal and run sudo apt update followed by sudo apt install python3.
- Fedora/RHEL-based systems: Use sudo dnf install python3.
- Arch Linux: Use sudo pacman -S python.
Verifying the Installation
- After installation, type python3 --version to confirm the installed version.
- You can also check that pip (Python's package installer) is available by typing pip3 --version.
🍎 Installing Python on macOS
macOS comes with Python 2.x pre-installed on older versions, but Python 3 is recommended for all new projects.
Option 1: Using the Official Installer
- Visit the official Python website at python.org.
- Download the latest Python 3 installer for macOS.
- Open the downloaded .pkg file and follow the installation wizard.
- Once installed, open Terminal and type python3 --version to verify.
Option 2: Using Homebrew
- If you have Homebrew installed, open a terminal and run brew install python.
- Homebrew will install the latest Python 3 and set it up automatically.
- Verify with python3 --version.
🪟 Installing Python on Windows
Windows does not come with Python pre-installed, but installation is straightforward.
Using the Official Installer
- Go to python.org and download the latest Python 3 installer for Windows.
- Run the installer and check the box that says "Add Python to PATH" at the bottom of the setup window.
- Click Install Now and wait for the installation to finish.
- After installation, open Command Prompt and type python --version to confirm.
Using the Microsoft Store
- Open the Microsoft Store from your Start menu.
- Search for Python and select the latest version (e.g., Python 3.12).
- Click Get or Install and wait for the process to complete.
- Verify by typing python --version in Command Prompt.
🔄 Comparison of Installation Methods
| Operating System | Recommended Method | Ease of Use | Package Manager Support |
|---|---|---|---|
| Linux | Package manager (apt, dnf, pacman) | Easy | Yes |
| macOS | Official installer or Homebrew | Easy | Yes (via Homebrew) |
| Windows | Official installer with PATH option | Very Easy | No (but pip works) |
🛠️ Verifying Your Installation
Once Python is installed, run these checks to ensure everything is working.
- Check Python version: Type python --version (Windows) or python3 --version (Linux/macOS).
- Check pip version: Type pip --version or pip3 --version.
- Run a simple test: Type python -c "print('Hello, Python!')" and you should see the message printed.
⚙️ What is pip and Why Do You Need It?
pip is Python's package installer. It allows you to install additional libraries and tools that extend Python's functionality.
- pip comes bundled with Python 3.4 and later versions.
- To install a package, use pip install package_name.
- To see what packages are already installed, use pip list.
- To update pip itself, use pip install --upgrade pip.
🕵️ Troubleshooting Common Issues
If something doesn't work after installation, here are a few things to check.
- "Python is not recognized" on Windows: You likely forgot to check "Add Python to PATH" during installation. Re-run the installer and make sure that box is checked.
- Multiple Python versions: If you have both Python 2 and Python 3, use python3 on Linux/macOS or py on Windows to specify Python 3.
- Permission errors on Linux/macOS: Use sudo before your install command if you get permission denied errors.
- Firewall or proxy blocking downloads: If you're behind a corporate firewall, you may need to configure proxy settings or use an offline installer.
✅ Summary
- Python can be installed on Linux, macOS, and Windows using simple methods.
- Always verify your installation by checking the version and testing a basic command.
- pip is automatically included and is essential for managing Python packages.
- If you run into issues, check your PATH settings and permissions first.
With Python installed, you're now ready to start writing and running your first scripts.
Interactive Views
You are currently in 📚 All-in-One mode. Use the tabs at the top to switch to 📖 Theory Only or 💻 Code Only views.
This guide shows you how to install Python on the three major operating systems using command-line and installer methods.
💻 Example 1: Check if Python is already installed on your system
This example verifies whether Python is already present on your machine before installing.
# Open your terminal (Linux/macOS) or Command Prompt (Windows)
# Type the following command and press Enter:
python --version
📤 Output: Python 3.12.0 (or similar version number, or an error if not installed)
💻 Example 2: Install Python on Linux using the package manager
This example installs Python on Ubuntu/Debian-based Linux distributions using apt.
# Open terminal and run these commands one at a time:
sudo apt update
sudo apt install python3
python3 --version
📤 Output: Python 3.12.0
💻 Example 3: Install Python on macOS using Homebrew
This example installs Python on macOS using the Homebrew package manager.
# Open Terminal and run these commands one at a time:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
brew install python
python3 --version
📤 Output: Python 3.12.0
💻 Example 4: Install Python on Windows using the official installer
This example downloads and installs Python on Windows using the executable installer from python.org.
# Step 1: Open a web browser and go to:
# https://www.python.org/downloads/
# Step 2: Click the "Download Python 3.x.x" button
# Step 3: Run the downloaded installer file
# Step 4: Check the box "Add Python to PATH"
# Step 5: Click "Install Now"
# Step 6: Open Command Prompt and verify:
python --version
📤 Output: Python 3.12.0
💻 Example 5: Verify Python installation with a simple script
This example confirms Python is working by running a one-line program.
# Create a new file called hello.py with this content:
print("Python is installed and working!")
# Then run it from the terminal:
python hello.py
📤 Output: Python is installed and working!
📊 Comparison Table: Python Installation Methods
| Operating System | Method | Command/Steps | Verification Command |
|---|---|---|---|
| Linux (Ubuntu/Debian) | Package Manager (apt) | sudo apt install python3 |
python3 --version |
| macOS | Homebrew | brew install python |
python3 --version |
| Windows | Official Installer | Download from python.org, run installer | python --version |
| Any OS | Check existing installation | python --version or python3 --version |
Shows version or error |
| Any OS | Run test script | Create hello.py with print("...") |
python hello.py |