Python - Installation

Overview

Estimated time: 30–45 minutes

Install Python 3, choose a version, and prepare your environment for development across Windows, macOS, and Linux.

Learning Objectives

  • Install Python 3.12+ on your OS (or manage versions with pyenv/conda).
  • Verify installation and PATH, and understand the difference between python and python3.
  • Set up a basic developer-friendly configuration.

Prerequisites

Installing Python

Option A: Official installers

  • Windows/macOS: download from python.org; ensure “Add to PATH” (Windows) is checked.
  • Linux: use your distro package manager (may be older) or install from source.

Option B: pyenv (recommended for multiple versions)

# macOS (Homebrew)
brew update && brew install pyenv
pyenv install 3.12.4
pyenv global 3.12.4
python --version

Expected Output:

Python 3.12.4

Option C: Conda (Anaconda/Miniconda)

# Create an environment with a specific Python version
conda create -n py312 python=3.12 -y
conda activate py312
python --version

Verify PATH and commands

python --version   # or: python3 --version
which python       # macOS/Linux
where python       # Windows

Common Pitfalls

  • Multiple Pythons on PATH causing confusion (system vs pyenv vs conda). Prefer per-project venvs.
  • Using python when the OS expects python3 (or vice versa). Verify with --version.
  • Missing developer tools (e.g., build tools for certain packages). Install Xcode CLT (macOS) or build-essentials (Linux).

Checks for Understanding

  1. How do you confirm which python binary is executed by default?
  2. Which tool would you use if you need multiple Python versions installed side-by-side?
Show answers
  1. Run which python (macOS/Linux) or where python (Windows) and check python --version.
  2. pyenv or conda environments.

Exercises

  1. Install Python 3.12+ and print the version using the CLI.
  2. (Optional) Install pyenv and install at least two Python versions; switch between them.