Ch 1.2 Python Installation Guide
The first step to starting Python development is installing the Python interpreter. Installation methods differ by operating system, and this chapter also introduces pyenv for managing multiple versions.
1. Windows Installation
Method 1: Official Installer (Recommended)
- Download the latest version from python.org/downloads
- Be sure to check "Add Python to PATH" during installation
- Click "Install Now" or "Customize installation"
# Verify installation
python --version
# Python 3.12.x
python3 --version
# Python 3.12.x (or the same version)
# Check pip
pip --version
Important: On Windows, both
pythonandpython3commands point to the same Python 3. PATH must be configured for this to work.
Method 2: winget Package Manager
You can install Python using winget, which is built into Windows 10/11.
# Install Python via winget
winget install Python.Python.3.12
# Restart the terminal after installation
python --version
Manual PATH Configuration on Windows
If automatic configuration did not work:
- Go to System Environment Variables → Edit Path
- Add the following two paths:
C:\Users\YourUsername\AppData\Local\Programs\Python\Python312\C:\Users\YourUsername\AppData\Local\Programs\Python\Python312\Scripts\
2. macOS Installation
Method 1: Homebrew (Recommended)
# Install Homebrew first (if not already installed)
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
# Install Python
brew install python@3.12
# Verify installation
python3 --version
pip3 --version
macOS System Python Caution
macOS includes a built-in system Python (/usr/bin/python3).
# System Python path (do not modify)
which python3
# /usr/bin/python3
# Python installed via Homebrew (use this one)
# /opt/homebrew/bin/python3 (Apple Silicon)
# /usr/local/bin/python3 (Intel Mac)
Warning: macOS system Python is used internally by the operating system. Never install packages into the system Python using
sudo pip install. Always use a virtual environment or the Homebrew-installed Python.
3. Linux Installation
Ubuntu / Debian (apt)
# Update package list
sudo apt update
# Install Python
sudo apt install python3 python3-pip python3-venv
# deadsnakes PPA — install latest version (Ubuntu)
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update
sudo apt install python3.12 python3.12-venv python3.12-dev
# Verify installation
python3.12 --version
CentOS / RHEL / Fedora (yum/dnf)
# Fedora
sudo dnf install python3 python3-pip
# CentOS 8+ / RHEL 8+
sudo dnf install python38 # or python39, python311
# Verify installation
python3 --version
4. pyenv — Managing Multiple Versions
Use pyenv to manage different Python versions on a per-project basis.
Installing pyenv
# macOS / Linux
curl https://pyenv.run | bash
# Add to shell config file (~/.bashrc or ~/.zshrc)
export PYENV_ROOT="$HOME/.pyenv"
[[ -d $PYENV_ROOT/bin ]] && export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"
# Apply configuration
source ~/.bashrc # or source ~/.zshrc
Key pyenv Commands
# List available Python versions
pyenv install --list
# Install a specific version
pyenv install 3.12.3
pyenv install 3.11.9
# List installed versions
pyenv versions
# * system
# 3.11.9
# 3.12.3
# Set the global default version
pyenv global 3.12.3
# Set a version for a specific project directory
cd my-project
pyenv local 3.11.9
# Check the currently active version
pyenv version
# 3.11.9 (set by /home/user/my-project/.python-version)
Using pyenv local creates a .python-version file in the directory.
5. Verifying the Installation
# Check Python version
python --version
python3 --version
# Check pip version
pip --version
pip3 --version
# Find Python executable location
which python3 # macOS/Linux
where python # Windows
# Test Python REPL
python3 -c "print('Python installation successful!')"
# View Python info
python3 -c "import sys; print(sys.version); print(sys.executable)"
# Verify directly in the Python REPL
import sys
print(f"Python version: {sys.version}")
print(f"Executable path: {sys.executable}")
print(f"Platform: {sys.platform}")
py LauncherThe pyenv-virtualenv plugin lets you manage both versions and virtual environments together.
# pyenv-virtualenv is already installed if you used pyenv.run
# Create a virtual environment with a specific Python version
pyenv virtualenv 3.12.3 my-project-env
# Activate the virtual environment
pyenv activate my-project-env
# Set auto-activation for a project directory
cd my-project
pyenv local my-project-env
# Now the virtual environment activates automatically when you enter the directory!
# List virtual environments
pyenv virtualenvs
Windows py Launcher usage:
On Windows, the py command lets you specify the Python version to run.
# Run the latest Python 3
py -3
# Run a specific version
py -3.12
py -3.11
# Run a script
py -3.12 script.py
# List installed versions
py --list
Now that Python is installed, it is time to set up a development environment for writing code comfortably. The next chapter covers how to configure VS Code, PyCharm, and Jupyter Notebook.