Computer Vision with Deep Learning / Start Here

Set up the pinned CPU environment

Lesson 2 of 36. Open to read. No account needed.

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:

LibraryVersionUsed for
torch2.14.1, CPU buildTensors, models and training
torchvision0.29.1, CPU buildImage decoding, transforms, datasets and pretrained models
NumPy2.5.4Arrays outside PyTorch
Pillow12.3.0Image files, used by torchvision
Matplotlib3.11.2Charts and image grids saved as PNG files
torchmetrics1.9.0The reference evaluator for detection scores
pycocotools2.0.11The official COCO evaluation behind torchmetrics
pytest9.1.1Supplied 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.

The practice folder. Inside your home folder, cv-practice holds five things: .venv, the course environment with the eight pinned libraries, kept for the whole course; requirements.txt with the exact versions; weights, the folder TORCH_HOME points to, where pretrained weights are downloaded once and reused; data, the EuroSAT download shared by lessons; and one folder per lesson, removed after the lesson. The computer's own Python stays outside and unchanged.

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.

  1. Create and activate the environment. macOS and Linux:

    mkdir -p ~/cv-practice
    cd ~/cv-practice
    python3 -m venv .venv
    source .venv/bin/activate
    

    Windows PowerShell:

    mkdir $HOME\cv-practice
    cd $HOME\cv-practice
    python -m venv .venv
    .venv\Scripts\Activate.ps1
    

    Your prompt now starts with (.venv). From here on the command is python on every platform. If PowerShell refuses to run Activate.ps1, see the note after the troubleshooting table.

  2. Save this as requirements.txt in cv-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
    
  3. 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 check
    

    The first command reads only PyTorch's CPU index; the second reads only PyPI. In the second step pip reports Requirement already satisfied for torch and torchvision, with the installed version 2.14.1+cpu on Linux and Windows: the +cpu label marks the CPU build, and ==2.14.1 accepts it. The last command prints No broken requirements found.

  4. 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_HOME again before running a lesson's scripts; each lesson's starting state reminds you.

  5. 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-environment
    

    Windows PowerShell:

    mkdir $HOME\cv-practice\set-up-the-environment
    cd $HOME\cv-practice\set-up-the-environment
    

    Save 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 seeLikely causeNext step
ERROR: Package 'torchvision' requires a different Python: 3.14.1 not in '!=3.14.1,>=3.10'Python 3.14.1Install another 3.14 release, or 3.12 or 3.13, and recreate .venv
python3 -m venv says ensurepip is not availableDebian and Ubuntu package venv separatelyInstall python3-venv, then repeat step 1
torch build: CUDA ..., or nvidia- packages downloading in step 3torch came from PyPI instead of the CPU indexRemove .venv, recreate it and run step 3 with the first command first
Weights cache inside the practice folder: False and TORCH_HOME: not setTORCH_HOME not set in this terminalRun step 4 again in this terminal
ModuleNotFoundError: No module named followed by one of the librariesThe environment is not activeActivate it as in step 1
A library line ends with expected ...Another version installedRun 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.

  1. Clean up the lesson folder, keeping the environment. macOS and Linux:

    cd ~/cv-practice
    ls
    rm -rf set-up-the-environment
    

    Windows PowerShell:

    cd $HOME\cv-practice
    ls
    Remove-Item -Recurse set-up-the-environment
    

    Check that ls shows set-up-the-environment before you remove it, and leave .venv and requirements.txt in 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

  1. Why does the setup install torch from the CPU index before reading requirements.txt from PyPI, and what would the reverse order risk?
  2. A learner on Linux sees torch build: CUDA and a version number. What happened, and what is the fix?
  3. 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

  1. 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.txt from 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.
  2. 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 reports torch build: CPU.
  3. 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.

References

31 more lessons in the full course

Course access opens every lesson and adds revision notes, the Quick Reference, saved progress, bookmarks and your own notes.

INR 199 plus 18% GST. 90 days of online access. No auto-renewal.

Get the full course

This website is operated by VECTAMETRIC EDTECH (OPC) PRIVATE LIMITED, operating as Vectametric.

Corporate Identity Number (CIN): U85499KA2026OPC229822. GSTIN: 29AAMCV8281D1ZS. Registered office: RS NO/38/2A/1 BASTAND, ROAD MAHANTESH NAGAR, Ramdurg, Ramdurg, Belgaum- 591123, Karnataka.

Queries and grievances: Prajval Honnungar, Grievance Officer and Data Protection Contact.

Telephone: +91 94800 09310. Support: support@vectametric.com. Grievances: support@vectametric.com.

Copyright 2026 VECTAMETRIC EDTECH (OPC) PRIVATE LIMITED. All rights reserved.

Vectametric home · Roadmaps · Vecta IT Exams · Vecta Government Exams · Vecta Banking & Finance Exams · Vecta Entrance Exams · About us · Contact · Privacy Policy · Terms and Conditions · No-Refund Policy