Generative AI and Large Language Model Fundamentals / Start Here

Set up an owned CPU practice environment

Lesson 3 of 33. Open to read. No account needed.

A package can be installed successfully and still be unavailable to your program. That happens when installation and execution use different Python interpreters. This lesson creates one owned practice environment, installs the course's exact CPU package set and checks that your script is using it. You will not download a model or generate text yet.

Separate the base interpreter from the practice files

An interpreter is the Python program that runs your code. A package adds Python modules and, sometimes, compiled components. A virtual environment keeps packages for one task separate from other projects. It depends on a base Python installation; it is not a copy of an entire operating system.

The standard-library venv module creates .venv/ inside our practice folder. Its interpreter is .venv/bin/python. Invoking that path explicitly makes the installation target and execution target visible. Shell activation is an optional convenience that changes which python command is found first; we do not need activation here.

Base CPython outside the owned practice folder creates its isolated environment; inside the folder, keep model files and supplied inputs separate from replaceable outputs.

The arrow means base Python creates the virtual environment. The dashed boundary identifies the practice folder, not a security sandbox.

The environment holds packages, model/ will hold verified downloaded files, inputs/ will hold supplied fictional data, and outputs/ will hold run records. These folders have different lifetimes. Recreating packages should not require deleting model inputs or results you want to keep. Base Python stays outside the practice cleanup boundary. We will leave the three data folders empty in this lesson.

Confirm the starting machine

Use Bash on Linux x86_64 with an installed CPython 3.13 interpreter and working venv support. The reference run uses CPython 3.13.15 and glibc 2.43; glibc is the system C library used by compiled Linux packages. These commands do not establish compatibility for another operating system, architecture or Python minor version. The CPU wheel carries a manylinux_2_28 compatibility tag, but a wheel tag alone does not prove every matching machine works.

The learner supplies the base interpreter, terminal, initial internet connection and writable disk. If CPython 3.13 or its venv component is absent, obtain it through your Linux software provider or administrator before this exercise. Do not replace the operating system's Python to satisfy the course, and do not run course package installation with sudo. Reading the lesson does not require installing anything.

Allow about 8 GB RAM and 3 GB free disk as planning budgets, not tested minimums. The environment and eventual model occupy space in addition to download and installation overhead. A successful install is not a minimum-spec hardware trial. This path needs no GPU, service account, API key or paid API. Downloads are public Python packages; your normal network/data charges still apply.

In Bash, set the interpreter command and inspect it:

GENAI_PYTHON=python3.13
"$GENAI_PYTHON" --version
"$GENAI_PYTHON" -c "import platform, sys; print(sys.executable); print(platform.system(), platform.machine(), platform.libc_ver())"

GENAI_PYTHON is a shell variable naming your installed base interpreter. If python3.13 is not on your command search path, set the variable to the quoted absolute executable path from your installation instead. The -c argument runs the short Python statements shown; platform reports the machine and sys.executable identifies the running interpreter. Continue only with CPython 3.13 on the stated Linux architecture. Paths and glibc details can differ; record them rather than assuming a command called python is right.

Create the owned root, enter it and inspect the location:

mkdir -p ~/genai-llm-practice
cd ~/genai-llm-practice
pwd -P
ls -la

~ denotes your home folder; pwd -P prints the resolved working directory. If this location contains unrelated work, choose a fresh owned folder and adjust subsequent course paths consistently. Do not overwrite another project. If it already contains this course's .venv/, use the resumption section before recreating it. For a new practice folder, continue:

mkdir -p model inputs outputs
"$GENAI_PYTHON" -m venv .venv
.venv/bin/python --version
.venv/bin/python -m pip --version

mkdir -p creates missing folders and leaves existing ones in place. -m venv runs Python's environment-creation module; wait for it to finish before using the new interpreter. The last command runs the package installer pip through that same interpreter. Its reported location should be inside this .venv/. It does not install course packages yet. A missing venv/ensurepip error means the base Python installation needs its environment support supplied.

Supply the complete package pins

A pin fixes a package version, written as name==version. Direct packages such as Transformers need other packages; these dependencies are pinned as well so the reference exercise does not silently resolve a different set. The version numbers below belong to this course snapshot, not a general instruction to freeze all future projects forever.

In the practice root, save this complete UTF-8 file as requirements-cpu.txt. It is reproduced from the maintained example examples/cpu-environment/requirements-cpu.txt; no source-pack download is needed. Keep the plain filename and one package per line.

annotated-doc==0.0.5
anyio==4.15.1
click==8.5.0
filelock==3.32.3
fsspec==2026.7.0
h11==0.16.0
hf-xet==1.7.0
httpcore2==2.13.1
httpx2==2.13.1
huggingface_hub==2.2.0
idna==3.20
Jinja2==3.1.6
markdown-it-py==4.2.0
MarkupSafe==3.0.3
mdurl==0.1.2
mpmath==1.3.0
networkx==3.6.1
numpy==2.5.4
packaging==26.3
Pygments==2.21.0
PyYAML==6.0.3
regex==2026.9.29
rich==15.0.0
safetensors==0.8.0
setuptools==78.1.0
shellingham==1.5.4
sympy==1.14.0
tokenizers==0.23.3
tqdm==4.70.1
transformers==5.19.0
truststore==0.10.5
typer==0.27.3
typing_extensions==4.16.0

Transformers supplies model/tokenizer APIs; tokenizers implements tokenisation, safetensors reads the selected weight format, huggingface_hub obtains the public files, and NumPy supplies numerical arrays. The other entries satisfy their runtime dependencies and the reference package set. For example, Jinja2 supports text templates. You need not use every package directly in your script, and the later lessons explain each API when they use it.

PyTorch is deliberately installed in its own command from the official CPU wheel index. A wheel is an installable package build; CPU and accelerator builds can have different contents. Then install the remaining pins from the Python Package Index (PyPI). Run these commands one at a time, in the practice root, and wait for each to succeed:

.venv/bin/python -m pip --isolated install --disable-pip-version-check --no-cache-dir torch==2.14.1 --index-url https://download.pytorch.org/whl/cpu
.venv/bin/python -m pip --isolated install --disable-pip-version-check --no-cache-dir -r requirements-cpu.txt --index-url https://pypi.org/simple
.venv/bin/python -m pip --isolated check --disable-pip-version-check

Each command uses one named index. --isolated ignores user pip configuration and environment options that might redirect installation. --no-cache-dir avoids leaving a persistent pip download cache for this exercise; it can make retries download again. Disabling pip's version check avoids an unrelated update query. -r reads our requirements file. The second install also checks compatibility with the already installed torch package and may replace initially resolved dependency versions with the explicit pins.

The requested torch release resolves to 2.14.1+cpu on this reference path; +cpu identifies the installed build. The full file pins 33 other packages. pip check should report No broken requirements found. This checks declared package dependencies, not the exact course pins, model files, generation or factual quality. We check the remaining environment conditions next.

Verify the interpreter and installed contents

Save the following complete file as check_environment.py in the practice root, alongside .venv/ and requirements-cpu.txt. Its maintained example is examples/cpu-environment/check_environment.py.

"""Save in the owned practice root beside requirements-cpu.txt and .venv/."""
import importlib.metadata
from pathlib import Path
import platform
import shutil
import sys

ROOT = Path(__file__).resolve().parent
print("practice folder:", ROOT)
print("interpreter:", sys.executable)
print("Python:", platform.python_version(), platform.python_implementation())
print("platform:", platform.system(), platform.machine(), platform.libc_ver())
if (ROOT / ".venv").is_symlink() or sys.prefix == sys.base_prefix or Path(sys.prefix).resolve() != (ROOT / ".venv").resolve():
    raise RuntimeError("Run this folder's .venv/bin/python, not another interpreter")
if platform.python_implementation() != "CPython" or sys.version_info[:2] != (3, 13):
    raise RuntimeError("This course path requires CPython 3.13")
if platform.system() != "Linux" or platform.machine() != "x86_64":
    raise RuntimeError("This command path is verified only on Linux x86_64")

expected = {"torch": "2.14.1+cpu"}
for line in (ROOT / "requirements-cpu.txt").read_text().splitlines():
    name, version = line.split("==")
    expected[name] = version
for name, version in expected.items():
    actual = importlib.metadata.version(name)
    if actual != version:
        raise RuntimeError(f"{name}: expected {version}, found {actual}")

import torch
import transformers

if torch.version.cuda is not None:
    raise RuntimeError("Expected the CPU PyTorch build")
for name in ["model", "inputs", "outputs"]:
    folder = ROOT / name
    if not folder.is_dir() or folder.is_symlink():
        raise RuntimeError(f"Expected an owned ordinary folder: {folder}")

print("torch / transformers:", torch.__version__, transformers.__version__)
print("CUDA build runtime:", torch.version.cuda)
print("checked package pins:", len(expected))
print("free disk GB:", round(shutil.disk_usage(ROOT).free / 1_000_000_000, 2))
print("ready: pinned CPU environment; model files and generation are separate checks")

The first block prints the saved script's root and current interpreter. Python stores the active environment location in sys.prefix and its base location in sys.base_prefix. The guard rejects a base interpreter, a different project's environment or a symlink used as this exercise's .venv/. Comparing resolved paths checks the target rather than trusting a folder's label. The next two guards enforce this command path's CPython version and platform.

The expected dictionary starts with the CPU torch build. Reading the supplied file and calling splitlines() yields its individual lines; split("==") separates each package name from its exact version. This file deliberately contains only those plain pin lines. importlib.metadata.version(name) reads the installed version; a mismatch raises an error naming that package. This verifies all 34 listed package pins rather than only printing a familiar name.

Importing torch and Transformers then checks that their actual modules can load. torch.version.cuda reports the CUDA runtime associated with a CUDA build; CUDA is software used for NVIDIA GPU computation. Here the expected value is None, because the reference wheel is CPU-only. Having no GPU on a machine is different from having installed the CPU build.

The final folder check expects ordinary owned model/, inputs/ and outputs/ directories, not symlinks into another project. shutil.disk_usage(ROOT).free reports available bytes on the current filesystem; dividing by one billion prints decimal gigabytes. It is a storage observation, not a measurement of peak installation or model memory requirements. This checker reads package metadata and folders and prints observations; it writes no model or result file.

Run it through the intended interpreter:

.venv/bin/python check_environment.py

Illustrative output is below. Your home path and free disk value will differ. The example path is not something to copy into a command.

practice folder: /home/learner/genai-llm-practice
interpreter: /home/learner/genai-llm-practice/.venv/bin/python
Python: 3.13.15 CPython
platform: Linux x86_64 ('glibc', '2.43')
torch / transformers: 2.14.1+cpu 5.19.0
CUDA build runtime: None
checked package pins: 34
free disk GB: 12.34
ready: pinned CPU environment; model files and generation are separate checks

Readiness means the correct interpreter, matching package pins, importable libraries, CPU build and expected folder boundaries, plus the separate successful pip check. Empty model/ is correct at this stage. There are no model weights to load yet, and no claim that generation has been tested by this checker. The next lesson obtains the fixed model inputs.

Diagnose the environment before changing it

ObservationNext check and reason
Command or interpreter not foundConfirm the base executable path, current folder and completed venv creation. Do not install into an arbitrary system Python.
ModuleNotFoundError or missing package metadataUse the explicit .venv/bin/python path and confirm both install commands succeeded.
Wrong pin or non-CPU buildInspect the named installed version and the exact index/requirements commands; correct this owned environment.
Dependency conflict from pip checkPreserve the error text and compare the complete pin file. Do not randomly upgrade packages to silence it.
No matching wheel or import error for a compiled libraryRecheck Python minor, architecture, Linux library compatibility and the package source; another platform is not verified by this path.
Download failure or insufficient spaceCheck connectivity/free disk and retry the failed install when resolved; a failed install is not readiness.

Try the wrong interpreter deliberately

After the correct check succeeds, predict what happens if you run the same file using the base interpreter, then try:

"$GENAI_PYTHON" check_environment.py

Do not install missing packages into base Python. Identify the evidence that lets you correct the command. Then return to .venv/bin/python check_environment.py and explain why a successful pip invocation from some other terminal was insufficient.

Hint

The guard runs before importing torch. Compare the printed executable, sys.prefix and sys.base_prefix, not just the fact that a program named Python started.

Answer and reasoning

The base interpreter is rejected with Run this folder's .venv/bin/python, not another interpreter. It may not have the packages, but the root error is the execution target. Running .venv/bin/python check_environment.py selects the environment into which the documented commands installed them. A different Python's successful installation says nothing about this target's readiness. The failure exercise changes no packages or files, so correcting the command is the reset.

Resume and clean up by ownership

On a new terminal, set GENAI_PYTHON again if needed and return to ~/genai-llm-practice. You do not need to reactivate an environment when using .venv/bin/python. If creation finished, inspect that interpreter before creating another environment. If installation was interrupted, retain the pin file, rerun the failed install command and repeat pip check and the checker. A partial install is not a reason to delete model files or supplied inputs.

Keep all four folders for subsequent lessons. If an owned environment must be rebuilt, first use pwd -P, inspect .venv/ in your file manager and confirm it is this course's ordinary directory. Close any running course Python processes, then remove only that .venv/ directory and recreate/install it with the steps above. Do not remove base Python, shared caches, model/, inputs/, outputs you want to keep, or the whole practice root as a routine fix. Do not move a venv and assume it remains usable: recreate it at its intended location.

Sources for this setup

28 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 999 plus 18% GST. 365 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