Python must be installed on your computer before you can write and run Python programs. This guide will walk you through the installation process for Windows, macOS, and Linux.
Before installing, check if Python is already on your system:
python --versionor
python3 --versionpython3 --versionIf you see output like Python 3.11.5 or similar, Python is already installed. If the version is 3.8 or higher, you're good to go! If not, follow the installation steps below.
- Go to the official Python website: https://www.python.org/downloads/
- Click the "Download Python 3.x.x" button (latest stable version)
- The website automatically suggests the correct version for Windows
- Important: Check the box "Add Python to PATH" at the bottom of the installer
- Click "Install Now" for standard installation
- Wait for the installation to complete
- Click "Close" when finished
Open Command Prompt (Win + R, type cmd, press Enter) and run:
python --versionYou should see output like:
Python 3.11.5
Also verify pip (Python's package manager):
pip --versionProblem: python command not recognized
Solution:
- Reinstall Python and ensure "Add Python to PATH" is checked
- Or manually add Python to PATH:
- Search for "Environment Variables" in Windows
- Edit "Path" under System Variables
- Add:
C:\Users\YourUsername\AppData\Local\Programs\Python\Python311\ - Add:
C:\Users\YourUsername\AppData\Local\Programs\Python\Python311\Scripts\
macOS comes with Python 2.7 pre-installed, but you need Python 3.x for modern development.
- Go to https://www.python.org/downloads/
- Download the latest macOS installer
- Open the
.pkgfile and follow the installation wizard - Complete the installation
If you have Homebrew installed:
brew install python3If you don't have Homebrew, install it first:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"Open Terminal and run:
python3 --versionOutput should be:
Python 3.11.5
Check pip:
pip3 --versionAdd to your ~/.zshrc or ~/.bash_profile:
alias python=python3
alias pip=pip3Then reload:
source ~/.zshrcNow you can use python instead of python3.
Most Linux distributions come with Python 3 pre-installed. If not, follow these steps:
sudo apt update
sudo apt install python3 python3-pipsudo dnf install python3 python3-pipsudo pacman -S python python-pippython3 --version
pip3 --version- Python 2: End of life (January 2020) - DO NOT USE
- Python 3: Current version - USE THIS
- Minimum: Python 3.8+
- Recommended: Python 3.10 or 3.11
- Latest: Check python.org
# Check Python version in code
import sys
print(sys.version)
print(f"Python {sys.version_info.major}.{sys.version_info.minor}")Always upgrade pip to the latest version:
# Windows
python -m pip install --upgrade pip
# macOS/Linux
python3 -m pip install --upgrade pip# Virtual environment support (usually pre-installed)
pip install virtualenv
# Code formatting tool
pip install black
# Linter
pip install pylintCreate a test file to verify everything works:
# test.py
print("Python is working! π")
print(f"Python version: {__import__('sys').version}")
# Test basic functionality
numbers = [1, 2, 3, 4, 5]
squared = [n**2 for n in numbers]
print(f"Squared numbers: {squared}")# Windows
python test.py
# macOS/Linux
python3 test.pyPython is working! π
Python version: 3.11.5 (main, ...)
Squared numbers: [1, 4, 9, 16, 25]
Cause: Python not added to PATH Solution: Reinstall and add to PATH, or add manually
Cause: Having both Python 2 and 3 installed
Solution: Always use python3 and pip3 commands
Cause: Trying to install system-wide without privileges
Solution: Use pip install --user <package> or virtual environments
Cause: Outdated certificates Solution:
pip install --trusted-host pypi.org --trusted-host files.pythonhosted.org <package>Now that Python is installed, you're ready to set up your code editor!
π Installing Visual Studio Code β
python --version # or python3 --versionpip --version # or pip3 --versionpython -m pip install --upgrade pippip install package_namepython script.pypython
>>> print("Hello")
>>> exit()Congratulations! Python is now installed on your system. You're one step closer to becoming a Python developer! π