Why the Course Pins Eight Libraries
Every value a lesson asks you to compare came from exact library versions. A different torchvision can change a default, a pretrained weight file or the last digits of a result, and then a correct script looks wrong. So you will install exactly these:
| Library | Version | Used for |
|---|---|---|
| torch | 2.14.1, CPU build | Tensors, models and training |
| torchvision | 0.29.1, CPU build | Image decoding, transforms, datasets and pretrained models |
| NumPy | 2.5.4 | Arrays outside PyTorch |
| Pillow | 12.3.0 | Image files, used by torchvision |
| Matplotlib | 3.11.2 | Charts and image grids saved as PNG files |
| torchmetrics | 1.9.0 | The reference evaluator for detection scores |
| pycocotools | 2.0.11 | The official COCO evaluation behind torchmetrics |
| pytest | 9.1.1 | Supplied tests in two lessons |
They go into a virtual environment, a folder with its own python and
its own libraries, so nothing else on your computer is affected.

Read the diagram from the top. .venv and requirements.txt work as in any
Python project. The two folders that are new for this course are weights
and data. Pretrained networks are files of tens of megabytes; torchvision
downloads each one the first time a lesson asks for it and keeps it in a
cache. Keeping that cache inside the practice folder means it is reused by
every lesson, you can see what was downloaded, and removing the practice
folder at the end removes it too.
Which Python and Which Computer
The course supports Python 3.12 to 3.14, except 3.14.1. NumPy 2.5.4 needs 3.12 or later, PyTorch 2.14.1 publishes ready-built packages up to 3.14, and torchvision 0.29.1 refuses 3.14.1 exactly, because of a problem in that one Python release. The packages exist for 64-bit Linux, Windows 10 or 11 on x64, and macOS 14 or later on Apple silicon; an Intel Mac has no PyTorch 2.14.1 package.
Check your Python. On macOS and Linux:
python3 --version
In Windows PowerShell:
python --version
Illustrative output:
Python 3.13.15
If the command is missing or the version is outside the range, install a
supported Python from python.org/downloads or your system's package manager
first. On Debian and Ubuntu, also install the python3-venv package.
Why the CPU Index
PyTorch publishes two kinds of package. On Linux, the ordinary package from PyPI, Python's default package index, is a 555 MB build for NVIDIA graphics cards, and it pulls in more than 1 GB of further NVIDIA libraries that this course never uses. PyTorch's own CPU index has packages built for the processor alone; its torch package for Linux is 196 MB. The setup installs torch and torchvision from the CPU index first, then everything else from PyPI. The order matters: the second step finds torch already installed and keeps it, and it upgrades the NumPy that the CPU index supplied (2.5.2) to the pinned 2.5.4.
Exercise: Create the Course Environment
You will create the practice folder, the environment and the pinned
libraries, point the weights cache at the practice folder, then confirm with
a check script that everything is the right version in the right place. The
weights and data folders themselves appear when a later lesson first
downloads into them.
Starting state: a supported Python; no cv-practice folder yet. The
environment takes about 1.1 GB of disk and the download a few minutes, so
this is the one exercise that needs a fast network.
Effects: creates ~/cv-practice with .venv (about 1.1 GB) and
requirements.txt, and the lesson folder with check_setup.py. Packages
are downloaded from PyPI and download.pytorch.org. pip also keeps the
downloaded files in its own cache (python -m pip cache dir shows where;
python -m pip cache purge empties it); nothing else on the computer
changes, and nothing is uploaded. TORCH_HOME lasts only for the current
terminal.
Output: Outputs shown below are illustrative. The versions, Python supported, torch build: CPU and the last line should match; your Python
patch version, folder paths and thread count can differ.
-
Create and activate the environment. macOS and Linux:
mkdir -p ~/cv-practice cd ~/cv-practice python3 -m venv .venv source .venv/bin/activateWindows PowerShell:
mkdir $HOME\cv-practice cd $HOME\cv-practice python -m venv .venv .venv\Scripts\Activate.ps1Your prompt now starts with
(.venv). From here on the command ispythonon every platform. If PowerShell refuses to runActivate.ps1, see the note after the troubleshooting table. -
Save this as
requirements.txtincv-practice:torch==2.14.1 torchvision==0.29.1 numpy==2.5.4 pillow==12.3.0 matplotlib==3.11.2 torchmetrics==1.9.0 pycocotools==2.0.11 pytest==9.1.1 -
Install in two steps, then check:
python -m pip install torch==2.14.1 torchvision==0.29.1 --index-url https://download.pytorch.org/whl/cpu python -m pip install -r requirements.txt python -m pip checkThe first command reads only PyTorch's CPU index; the second reads only PyPI. In the second step pip reports
Requirement already satisfiedfor torch and torchvision, with the installed version2.14.1+cpuon Linux and Windows: the+cpulabel marks the CPU build, and==2.14.1accepts it. The last command printsNo broken requirements found. -
Point the weights cache at the practice folder. macOS and Linux:
export TORCH_HOME="$HOME/cv-practice/weights"Windows PowerShell:
$env:TORCH_HOME = "$HOME\cv-practice\weights"Like activation, this lasts only for the current terminal. In every new terminal, activate the environment and set
TORCH_HOMEagain before running a lesson's scripts; each lesson's starting state reminds you. -
Create the lesson folder and the check script. macOS and Linux:
mkdir -p ~/cv-practice/set-up-the-environment cd ~/cv-practice/set-up-the-environmentWindows PowerShell:
mkdir $HOME\cv-practice\set-up-the-environment cd $HOME\cv-practice\set-up-the-environmentSave this as
check_setup.py:"""Check the course environment: Python, the pinned libraries, the CPU build and the weights cache.""" import os import sys from pathlib import Path import matplotlib import numpy import PIL import pycocotools import pytest import torch import torchmetrics import torchvision from importlib.metadata import version print("Python:", sys.version.split()[0]) print("Python supported:", (3, 12) <= sys.version_info[:2] <= (3, 14) and sys.version_info[:3] != (3, 14, 1)) print("Environment:", sys.prefix) expected = { "torch": ("2.14.1", torch.__version__.split("+")[0]), "torchvision": ("0.29.1", torchvision.__version__.split("+")[0]), "numpy": ("2.5.4", numpy.__version__), "pillow": ("12.3.0", PIL.__version__), "matplotlib": ("3.11.2", matplotlib.__version__), "torchmetrics": ("1.9.0", torchmetrics.__version__), "pycocotools": ("2.0.11", version("pycocotools")), "pytest": ("9.1.1", pytest.__version__), } for name, (wanted, found) in expected.items(): print(f"{name:<12} {found:<8}", "OK" if found == wanted else f"expected {wanted}") print("torch build:", "CPU" if torch.version.cuda is None else f"CUDA {torch.version.cuda}") print("Device:", "cuda" if torch.cuda.is_available() else "cpu", "| threads:", torch.get_num_threads()) cache = Path(torch.hub.get_dir()).parent practice = Path.home() / "cv-practice" print("TORCH_HOME:", os.environ.get("TORCH_HOME", "not set")) print("Weights cache:", cache) print("Weights cache inside the practice folder:", Path(os.path.abspath(cache)).is_relative_to(practice))Run it with
python check_setup.py. Illustrative output on Linux:Python: 3.13.15 Python supported: True Environment: /home/you/cv-practice/.venv torch 2.14.1 OK torchvision 0.29.1 OK numpy 2.5.4 OK pillow 12.3.0 OK matplotlib 3.11.2 OK torchmetrics 1.9.0 OK pycocotools 2.0.11 OK pytest 9.1.1 OK torch build: CPU Device: cpu | threads: 4 TORCH_HOME: /home/you/cv-practice/weights Weights cache: /home/you/cv-practice/weights Weights cache inside the practice folder: True
How the Check Script Works
The imports fail with ModuleNotFoundError if the environment is not
active, which is itself a useful check. torch.__version__ is
2.14.1+cpu on Linux and Windows, so the script splits off any + label
before comparing;
pycocotools has no version attribute, so its version comes from the
installed package's metadata. torch.version.cuda is None for a CPU build
and a version string for an NVIDIA build, which is how the script tells the
two apart. The thread count is how many processor threads PyTorch uses for
one operation; yours may differ.
torch.hub.get_dir() is where torchvision stores downloaded weights, in a
hub subfolder of TORCH_HOME; the script prints its parent. Without
TORCH_HOME the cache defaults to .cache/torch in your home folder, and
the last line says False.
Success: Python supported is True, all eight library lines end in
OK, the build is CPU, and the weights cache is inside the practice folder.
If something differs:
| What you see | Likely cause | Next step |
|---|---|---|
ERROR: Package 'torchvision' requires a different Python: 3.14.1 not in '!=3.14.1,>=3.10' | Python 3.14.1 | Install another 3.14 release, or 3.12 or 3.13, and recreate .venv |
python3 -m venv says ensurepip is not available | Debian and Ubuntu package venv separately | Install python3-venv, then repeat step 1 |
torch build: CUDA ..., or nvidia- packages downloading in step 3 | torch came from PyPI instead of the CPU index | Remove .venv, recreate it and run step 3 with the first command first |
Weights cache inside the practice folder: False and TORCH_HOME: not set | TORCH_HOME not set in this terminal | Run step 4 again in this terminal |
ModuleNotFoundError: No module named followed by one of the libraries | The environment is not active | Activate it as in step 1 |
A library line ends with expected ... | Another version installed | Run step 3 again in the active environment |
Activating on Windows: you may first need to allow local scripts for
your account with Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser. It changes a Windows security setting for your account only;
read Microsoft's "About Execution Policies" page before running it.
Reset: the environment is disposable because requirements.txt
describes it. To rebuild it, run deactivate, check with ls -a (ls -Force on Windows) that you are in cv-practice and see .venv, remove
.venv (rm -rf .venv, or Remove-Item -Recurse -Force .venv), and repeat
steps 1 and 3. The weights folder can stay; it holds downloads only.
-
Clean up the lesson folder, keeping the environment. macOS and Linux:
cd ~/cv-practice ls rm -rf set-up-the-environmentWindows PowerShell:
cd $HOME\cv-practice ls Remove-Item -Recurse set-up-the-environmentCheck that
lsshowsset-up-the-environmentbefore you remove it, and leave.venvandrequirements.txtin place for every later lesson.
Independent task: open a new terminal, activate the environment but do
not set TORCH_HOME, and run the check script again; if you have already
done step 6, save check_setup.py in the lesson folder again first.
Predict the last three lines first.
Hint 1: Which settings belong to a terminal rather than to the environment folder?
Hint 2: Without TORCH_HOME, torch.hub.get_dir() falls back to a
default folder inside your home folder.
Check Your Understanding
- Why does the setup install torch from the CPU index before reading
requirements.txtfrom PyPI, and what would the reverse order risk? - A learner on Linux sees
torch build: CUDAand a version number. What happened, and what is the fix? - Why does pip refuse torchvision 0.29.1 on Python 3.14.1 but install it on 3.14.2?
Answer and Reasoning
Independent task
TORCH_HOME: not set
Weights cache: /home/you/.cache/torch
Weights cache inside the practice folder: False
TORCH_HOME is an environment variable, and a new terminal starts without
it, just as it starts without the environment activated. torchvision then
falls back to the default cache in your home folder, where downloads would
be invisible to the course and left behind by the final cleanup. Setting the
variable again fixes it.
Understanding check
- Installing torch and torchvision first from the CPU index puts the CPU
builds in place; the PyPI step then sees them already satisfied and only
adds the rest. In the reverse order, reading
requirements.txtfrom PyPI first would install the ordinary Linux torch package, the large NVIDIA build, because it is what PyPI offers. Each command uses one index, so the two sources are never mixed in one resolution. - torch was installed from PyPI rather than the CPU index, so the NVIDIA
build arrived. Remove
.venv, recreate it and run step 3 in order; the check then reportstorch build: CPU. - torchvision 0.29.1 declares the Python versions it accepts as
!=3.14.1,>=3.10, which excludes that one release and nothing else. pip reads the requirement before installing anything, so it refuses on 3.14.1 and accepts 3.14.2, 3.13 or 3.12; the course's own lower limit of 3.12 comes from NumPy 2.5.4.