3 Getting Started
You can read the book online without installing anything. To run the examples and work on the exercises, you will need a Python environment with the course packages. The first two chapters run on a CPU; you do not need a graphics card to begin.
3.1 Before the first lab
We use Python and PyTorch. Familiarity with basic Python will help: variables, functions, loops, and indexing. You can revisit the mathematics as it appears in the chapters. Keep a note of unfamiliar notation and bring questions to the sessions.
Each topic has a concepts chapter and a practical lab. Start with Linear Regression, then work through its lab. Read the explanations around the code before running it, and predict what will happen when you change an example.
3.2 Set up Python and the course packages
We use uv, a tool that manages Python environments and installs packages. An environment keeps the course’s packages together, separate from those used by other projects. We use Python 3.12, matching the version specified in the book repository.
Use the same commands to set up a new checkout or update an existing course environment after pulling changes.
3.2.1 1. Install uv and get the book files
Follow the official uv installation instructions for your operating system. Open a new terminal afterwards and check:
uv --versionDownload the book from its GitHub repository using Code → Download ZIP, then extract it. Alternatively, if you use Git:
git clone https://github.com/HealthML/deep-learning-book.gitIn your terminal, change into the downloaded book folder. It is the folder containing pyproject.toml. All setup commands below run from that folder.
3.2.2 2. Synchronize the environment and packages
uv sync --lockedThis creates .venv, downloads Python 3.12 if needed, and installs the course package and its dependencies. The project settings select CPU PyTorch wheels on Linux and Windows and the standard package source on macOS. The same command works on all three operating systems; you do not need to activate the environment or install packages individually.
The dependency list is in pyproject.toml; the committed uv.lock records the versions used by the course and its automated checks. Run uv sync --locked again after updating the book files to install any dependency changes.
| Package | What we use it for |
|---|---|
PyTorch (torch) |
Tensors, automatic differentiation, and neural networks |
NumPy (numpy) |
Numerical calculations |
Matplotlib (matplotlib) |
Plots and visualizations |
Jupyter (jupyter) |
Running code in interactive notebooks |
Course helpers (dlbook) |
Functions included with this book for its examples and figures |
Supporting dependencies, including PyYAML for reading configuration files, are installed automatically. Additional requirements for later topics will be explained when needed.
3.3 Check that you can run an example
Start Jupyter from the course environment on any operating system:
uv run --locked jupyter notebookIn the browser window that opens, create a Python notebook in the book folder and run:
import sys
import numpy as np
import matplotlib.pyplot as plt
import torch
import dlbook
print("Python:", sys.executable)
print("PyTorch:", torch.__version__)
x = torch.tensor([1.0, 2.0, 3.0])
print("Tensor calculation:", x * 2)The final line should display tensor([2., 4., 6.]). The Python path should point inside your course folder’s .venv. You can copy code cells from the online book into your notebook to explore them. Run related cells in order: later cells may use variables defined earlier. Save your work in your own notebook.
You can also use a Python editor such as VS Code. Select the interpreter inside the course folder’s .venv so that the editor uses the packages you installed here.
3.4 If something does not work
For a missing-package error, run uv sync --locked from the book folder, then check the selected Python interpreter or notebook kernel. Installing a package into one environment does not make it available in another.
When asking for help, include your operating system, the command or cell you ran, and the complete error message. If setup is taking time, bring the issue to the lab so we can work through it together.
The online chapters contain the explanations, code, and figures; you can continue reading while resolving installation problems. Instructions for building or contributing to the website are in the repository’s README.