"""Check that your computer is ready for the course labs. Standard Python only; nothing to install.
python check_setup.py
It checks: your Python version, that Ollama is running on this computer, which of the course's
models you have pulled (and the command for each one you have not), that a model can actually
answer, and the two optional Python packages some lessons use.
"""
import importlib.util
import json
import sys
import urllib.request
OLLAMA = "http://localhost:11434"
# The models the labs use, the chapters that need them, and their download sizes (from ollama list).
MODELS = [
("qwen2.5:3b", "How Models Generate; Agents in Production", "1.9 GB"),
("nomic-embed-text", "Tokens and Embeddings; Retrieval (RAG); Evals", "274 MB"),
("bge-m3", "Tokens and Embeddings", "1.2 GB"),
("qwen3:4b", "Evals; Agents in Production", "2.5 GB"),
("llama3.2:3b", "Evals; Agents in Production", "2.0 GB"),
("qwen2.5:3b-instruct-q8_0", "How Models Generate lesson 9 only", "3.3 GB"),
("qwen2.5:3b-instruct-fp16", "How Models Generate lesson 9 only", "6.2 GB"),
]
PACKAGES = [("tiktoken", "Tokens and Embeddings lessons 1 and 2"),
("torch", "How Models Generate lesson 4 (attention)"),
("transformers", "How Models Generate lesson 4 (attention)")]
def get(path, body=None):
data = json.dumps(body).encode() if body is not None else None
req = urllib.request.Request(OLLAMA + path, data=data, headers={"Content-Type": "application/json"})
return json.loads(urllib.request.urlopen(req, timeout=120).read())
ok = True
v = sys.version_info
print(f"Python {v.major}.{v.minor}.{v.micro}: {'ok' if v >= (3, 9) else 'too old, install 3.9 or newer'}")
ok &= v >= (3, 9)
try:
version = get("/api/version")["version"]
print(f"Ollama {version}: running at {OLLAMA}")
except Exception as e:
print(f"Ollama: NOT reachable at {OLLAMA} ({e.__class__.__name__}).")
print(" Start the Ollama app (macOS, Windows) or run 'ollama serve' (Linux), then run this again.")
sys.exit(1)
have = {m["name"] for m in get("/api/tags")["models"]}
have |= {n.split(":")[0] for n in have if n.endswith(":latest")}
print("\nModels:")
for name, where, size in MODELS:
if name in have:
print(f" [x] {name:<27} used in {where}")
else:
print(f" [ ] {name:<27} used in {where}")
print(f" get it with: ollama pull {name} ({size})")
if "qwen2.5:3b" in have:
reply = get("/api/generate", {"model": "qwen2.5:3b", "prompt": "The capital of France is", "raw": True,
"stream": False, "options": {"num_predict": 3, "temperature": 0}})
print(f"\nTest answer from qwen2.5:3b: {reply['response'].strip()!r} (it should mention Paris)")
print("\nOptional Python packages:")
for pkg, where in PACKAGES:
found = importlib.util.find_spec(pkg) is not None
print(f" [{'x' if found else ' '}] {pkg:<13} for {where}")
if not found:
print(f" get it with: pip install {pkg}")
print("\nReady for the labs." if ok else "\nFix the items above, then run this again.")