Skip to content

Install guide: Python, a virtual environment, and pip

Needed from M3 onward. This is your first local install: until now everything ran in the browser (Colab). Take it slowly: setup is the single most common place beginners get stuck, so we go one tiny step at a time, for Windows, macOS, and Linux separately. Nothing here can harm your computer.

What you're installing and why: - Python: the language itself, so you can run programs on your machine (not just in a browser). - A virtual environment (venv): a private box for this project's libraries, so different projects don't tread on each other. (Why it matters: without it, every pip install goes into one shared pile and versions clash. One venv per project keeps things clean, this is standard professional practice.) - pip: Python's tool for installing libraries (other people's code you can reuse). It comes with Python.

Official docs (verify they open): Python downloads, https://www.python.org/downloads/ · venv, https://docs.python.org/3/library/venv.html · pip, https://pip.pypa.io/.


Step 1: Install Python (3.10 or newer)

Windows

  1. Go to https://www.python.org/downloads/ and click Download Python 3.x.
  2. Run the installer. On the first screen, tick "Add python.exe to PATH" (this is the step everyone forgets, it lets you type python in any terminal). Then click Install Now.
  3. Open a new PowerShell window (Start → type PowerShell → Enter).

Check it worked:

python --version
Expected: Python 3.12.x (any 3.10+). If you instead see the Microsoft Store open, or python is not recognized, see Troubleshooting below.

macOS

The Python that ships with macOS is old. Install a current one, easiest is the official installer: 1. Go to https://www.python.org/downloads/Download Python 3.x → run the .pkg installer. 2. (Alternative, if you use Homebrew: brew install python .) 3. Open a new Terminal (⌘ + Space → Terminal).

Check it worked:

python3 --version
Expected: Python 3.12.x (any 3.10+). On macOS use python3 (and pip3), not python.

Linux (Debian/Ubuntu)

Python is usually present; install the venv/pip extras to be safe:

sudo apt update && sudo apt install -y python3 python3-venv python3-pip
Check it worked:
python3 --version
Expected: Python 3.10.x or newer. (Other distros: use your package manager, dnf, pacman, etc.)

Which command, python or python3? On Windows it's usually python. On macOS/Linux it's usually python3 (and pip3). Use whichever your "check it worked" step above accepted, and keep using that one throughout.


Step 2: Make a project folder

Pick the command for your terminal. (New to the terminal? See terminal.md.)

macOS / Linux:

mkdir ai-course && cd ai-course
Windows (PowerShell):
mkdir ai-course; cd ai-course
Expected: your terminal prompt now ends in ai-course. You're "inside" the project folder.


Step 3: Create a virtual environment

Run this inside your project folder:

macOS / Linux:

python3 -m venv .venv
Windows:
python -m venv .venv
Expected: no output, but a new hidden folder named .venv appears in the project. That folder is your private library box. (You only create it once per project.)


Step 4: Activate the virtual environment

Activating tells your terminal "use this project's box."

macOS / Linux:

source .venv/bin/activate
Windows (PowerShell):
.\.venv\Scripts\Activate.ps1
Expected: your prompt now starts with (.venv). That prefix means it's active. (You re-activate every time you open a new terminal for this project. To leave it, type deactivate.)

Windows error about "running scripts is disabled"? Run this once, then try activating again:

Set-ExecutionPolicy -Scope CurrentUser RemoteSigned
(Answer Y. This allows local scripts; it's safe for development.)


Step 5: Install a library with pip

With the venv active (you see (.venv)), install the rich library:

pip install rich
Expected: lines ending in something like Successfully installed rich-15.x markdown-it-py-… pygments-…. (pip installs rich plus the small things it depends on.)

Or install everything a project lists at once (when a requirements.txt exists):

pip install -r requirements.txt


Step 6: Check it worked

pip list
Expected: a table of installed packages that includes rich (e.g. rich 15.0.0). If rich is in the list, your install works and you're ready to code.


Troubleshooting

Symptom Fix
Windows: python opens the Microsoft Store, or "not recognized" You missed "Add python.exe to PATH". Re-run the installer → Modify → tick PATH, or reinstall and tick it on the first screen. Open a new terminal afterwards.
macOS: python says "command not found" Use python3 and pip3 instead.
pip not found but Python works Use python -m pip ... (Windows) or python3 -m pip ... (macOS/Linux), same thing, always available.
Windows: "running scripts is disabled" when activating Run Set-ExecutionPolicy -Scope CurrentUser RemoteSigned once (answer Y), then activate again.
Installed a library but Python "can't find it" Your venv probably isn't active, check for (.venv) in the prompt; re-run the activate command from Step 4.
Prompt has no (.venv) after activating You may have created .venv in a different folder. cd into the project folder and re-run activate.

Secrets hygiene (you'll need it at M4). Soon you'll have an API key: a secret password for an AI service. Keep it in a file named .env, load it from there, and never type it into your code or commit it to Git. This course's .gitignore already ignores .env, and each module ships a .env.example with placeholder values to copy. We set this up properly in M4.