Create check_setup.py — an environment check
Before training networks, you need the tools. We use PyTorch — the most popular library for neural networks in Python.
Install it (if you do not have it yet) and create check_setup.py. This tiny script just checks everything is ready:
import torch— loads PyTorch.torch.__version__— shows the version (confirms it is installed).torch.cuda.is_available()— checks for a GPU (a graphics card for speed). A GPU is not required — a CPU is perfectly fine for the whole course.
Verify. In a terminal:
python check_setup.py
You should see roughly (the version number may differ):
PyTorch version: 2.2.0
Using CPU (no GPU found — that is perfectly fine for this course).
If you have a CUDA GPU, the second line will be Using CUDA (GPU): ... — also good. Either case means: the environment works, you can keep learning.
Gotcha. You run the script and instead of a version you get:
Traceback (most recent call last): File "check_setup.py", line 3, in <module> import torch ModuleNotFoundError: No module named 'torch'This means PyTorch is not installed in this Python environment yet. The fix — install it:
pip install torch(Find the exact command for your system on pytorch.org — the CPU version is fine.) After installing, run
python check_setup.pyagain — the version should appear. ThisModuleNotFoundErroris the most common first hurdle; now you know what it means.