PyTorch runs on the CPU by default and only uses a GPU when three things line up: an NVIDIA driver on the machine, a PyTorch build compiled for a CUDA version that driver supports, and a Python environment where that build is the one being imported. When torch.cuda.is_available() says False, or import fails with an error about a c10 DLL, one of those three is wrong. The checks take a minute; the fix is nearly always a reinstall with the right command.
The diagnosis#
nvidia-smi # 1. driver: is there a GPU and a driver?
python -c "import torch; print(torch.__version__, torch.version.cuda, torch.cuda.is_available())" # 2. build
python -c "import sys; print(sys.executable)" # 3. environment: which Python ran that?
Line 1 must print a table with a driver version and a CUDA version in the top right. If the command is not found, there is no driver, and nothing else matters until there is.
Line 2 prints the PyTorch version, the CUDA version it was built for, and whether it can see the GPU. A version ending in +cpu, or torch.version.cuda printing None, means a CPU-only build: the GPU cannot be used by this install regardless of the driver.
Line 3 tells you which Python that was. If it is not the environment you think you are in, every install has been going elsewhere.
Cause 1: a CPU-only build#
On Linux, pip install torch from the default index gives a CUDA build. On Windows it gives a CPU-only build, and on any platform a package manager or requirements file may have pinned the CPU variant. The fix is to install from PyTorch’s own index with the CUDA version selected:
pip uninstall -y torch torchvision torchaudio
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu126
The cu126 part names the CUDA version the build targets. Use the official install selector on the PyTorch website to get the exact command for your OS, package manager and CUDA version; it changes with each release and this article will not track it. Then re-run the diagnosis; torch.version.cuda should now print a number.
Cause 2: driver too old for the build#
Each CUDA build needs a minimum driver version. The CUDA version in nvidia-smi‘s top-right corner is the highest that driver supports. If the PyTorch build’s CUDA version is higher than that, the GPU is not usable. Either update the driver, which is the better option, or install a PyTorch build for an older CUDA, which the install selector offers.
You do not need to install the CUDA toolkit separately for PyTorch. The pip wheels bundle the CUDA libraries they need; only the driver has to be on the system. Installing a full toolkit is a common detour that fixes nothing and occasionally creates conflicts.
Cause 3: the wrong environment#
Installed in one Python, running in another. The third diagnosis line shows the interpreter; make sure the install command used the same one:
python -m pip install torch ... --index-url ... # follows the interpreter, not the PATH
In VS Code, select the interpreter inside the environment; in Jupyter, choose the matching kernel. A notebook that says False while the terminal says True is always this.
Cause 4: no wheel for your Python version#
ERROR: Could not find a version that satisfies the requirement torch
On a brand-new Python release, PyTorch wheels take weeks to appear. Check the supported versions on the install page; if yours is too new, create an environment with the previous Python. This is why data-science environments tend to run one version behind the latest.
uv venv --python 3.12 .venv # or: conda create -n ml python=3.12
Windows: c10 and DLL errors#
OSError: [WinError 126] The specified module could not be found. Error loading "...\torch\lib\c10.dll"
PyTorch’s libraries depend on the Visual C++ runtime. Install the latest Microsoft Visual C++ Redistributable, then reinstall PyTorch. If the error persists, a mixed install — parts from one CUDA build and parts from another after a partial upgrade — is likely; uninstall all three packages and install them together in one command. Also check that no other software on the PATH ships a conflicting cudart or similar DLL.
WSL#
CUDA works inside WSL 2 with the Windows NVIDIA driver installed on the Windows side and nothing GPU-specific installed in the Linux side except PyTorch itself. If nvidia-smi works in WSL, follow the Linux instructions. If it does not, update the Windows driver and WSL, and do not install a Linux driver inside WSL; that breaks it.
Apple Silicon#
There is no CUDA on a Mac. PyTorch uses Apple’s Metal backend instead, and the device name is mps, not cuda:
device = "mps" if torch.backends.mps.is_available() else "cpu"
Code that hard-codes cuda fails on a Mac by design. Use a device selector that checks cuda, then mps, then falls back to cpu.
A portable device check#
import torch
def pick_device():
if torch.cuda.is_available():
return torch.device("cuda")
if torch.backends.mps.is_available():
return torch.device("mps")
return torch.device("cpu")
device = pick_device()
print(device)
if device.type == "cuda":
print(torch.cuda.get_device_name(0))
Questions people ask#
Do I need an NVIDIA GPU?
For CUDA, yes. AMD GPUs use the ROCm builds on Linux; Apple Silicon uses Metal. Intel GPUs have a separate backend. Without any of these, the CPU works for learning and small models.
Does conda avoid this?
Conda installs the CUDA runtime alongside PyTorch and handles the pairing, which avoids some pip pitfalls. The driver requirement and the environment confusion apply equally.
is_available is True but training is slow.
The model and the data must be moved to the device with .to(device). A model on the GPU with data on the CPU, or the reverse, either errors or silently runs on the CPU.
How do I check which GPU is in use?
torch.cuda.get_device_name(0) in Python, and nvidia-smi while training shows memory and utilisation.
Where to go next#
- PyTorch for beginners — once the device works.
- pip install scikit-learn not working — the other install failure.
- Python venv not working — for the wrong-environment case.