torch.cuda.is_available() Returns False: CUDA Not Available Fix
torch.cuda.is_available() returning False means PyTorch can’t use your NVIDIA GPU; here is how to find out which link is broken.
The short version: run two checks. If nvidia-smi fails, the NVIDIA driver is the problem: install or reinstall it and reboot. If nvidia-smi works, run python -c "import torch; print(torch.version.cuda)". If it prints None, you have the CPU-only build of PyTorch: uninstall it and reinstall with the CUDA command from the PyTorch install page, which adds --index-url https://download.pytorch.org/whl/cuXXX. In WSL, install only the Windows driver; in Docker, add the NVIDIA Container Toolkit and --gpus all.
The surprise: on Windows, plain pip install torch installs a PyTorch with no CUDA support at all, and nothing warns you.
Jake’s new graphics card was supposed to make the photo-tagging model fast. Ethan installed PyTorch with the usual pip command, ran the script, and it took four minutes per batch, exactly as long as before.
Jake: "Is the card dead?"
Ethan: "The card is fine. Python never asked it for anything. We installed the version of PyTorch that only knows the processor."
The 30-second diagnosis
CUDA in PyTorch needs four links to hold: a supported NVIDIA GPU, a working driver, a PyTorch build with CUDA, and a GPU your program is allowed to see. Run this, and the first line that looks wrong is your problem:
nvidia-smi
python -c "import torch; print(torch.__version__, torch.version.cuda, torch.cuda.is_available())"
python -c "import torch; print(torch.__file__)"
echo $CUDA_VISIBLE_DEVICES # Windows PowerShell: echo $env:CUDA_VISIBLE_DEVICES
| What you see | The broken link | Jump to |
|---|---|---|
nvidia-smi not found or “failed to communicate” | The driver | Fix the NVIDIA driver |
Version ends in +cpu, CUDA prints None | CPU-only PyTorch | Install the CUDA build |
CUDA version printed, is_available() False | GPU hidden or the driver too old | Hidden GPUs; driver age |
| Works in one terminal, not another | Two Python environments | One environment, one torch |
| Fails only in WSL or Docker | GPU not passed through | WSL; Docker |
Install the CUDA build of PyTorch
This is the cause most of the time, and the one behind “AssertionError: Torch not compiled with CUDA enabled”. On Windows, pip install torch fetches the CPU-only build. The CUDA builds live on PyTorch’s own package index, so you need the exact command from the install selector: choose your OS, Pip, Python and a CUDA version, then copy what it shows.
pip uninstall -y torch torchvision torchaudio
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cuXXX
# replace cuXXX with the CUDA version shown in the selector
Uninstall first. If you only run the new command, pip may decide the CPU build already satisfies “torch” and leave it in place. Then check again: the version should end in +cuXXX and torch.version.cuda should print a number.
You don’t need the separate CUDA Toolkit for this. The pip and conda builds carry their own CUDA libraries; the toolkit is only for compiling your own CUDA code. What you do need is a driver new enough for the CUDA version you picked.
Jake: "So the fix is one install command?"
Ethan: "One uninstall and one install. The trick is the extra address at the end, the one that points at the GPU version."
Fix the NVIDIA driver
If nvidia-smi isn’t found, or says “NVIDIA-SMI has failed because it couldn’t communicate with the NVIDIA driver”, PyTorch never had a chance. Download the current driver for your card (nvidia.com/drivers) and reboot.
On Linux, a driver that worked yesterday can stop after an update. The usual reasons:
- Kernel update: the driver module was built for the old kernel. Reinstall the driver (or let DKMS rebuild it) for the running kernel, then reboot.
- Secure Boot: it blocks driver modules that aren’t signed with a key your machine trusts. Enroll the key your distribution’s driver package offers, or turn Secure Boot off.
- nouveau: the open-source driver claimed the card first. NVIDIA’s installer normally blocks it; check
lsmod | grep nouveau.
On Windows, a Windows Update sometimes swaps NVIDIA’s driver for an older one. Reinstalling the current driver puts it back.
What the CUDA Version in nvidia-smi really means
The top-right corner of nvidia-smi shows “CUDA Version: 13.x” or similar. That isn’t a CUDA installation; it is the newest CUDA your driver can run. A PyTorch build for that version or any older one works with it. If you install a PyTorch build for a newer CUDA than the driver supports, is_available() returns False until you update the driver.
So the rule is simple: pick a CUDA build in the PyTorch selector that is the same as or older than the number in nvidia-smi, or update the driver first.
Jake: "The screen says CUDA 13. Did we install CUDA 13?"
Ethan: "No. It says our driver can handle up to 13. We still need a PyTorch that uses it."
One environment, one torch
“It works in one terminal but not the other” is nearly always two Python environments: a CUDA build in your virtual environment or conda environment, and a CPU build in the system Python, or the other way round. Find out which one is running:
python -c "import sys, torch; print(sys.executable); print(torch.__file__, torch.version.cuda)"
Run that in the same place your script runs: the terminal, the IDE, the Jupyter kernel. Jupyter is the classic trap: the notebook kernel can point at a different environment from the terminal you installed into. Install with python -m pip from inside the right environment, so pip and Python always match.
CUDA not available in WSL
In WSL, Linux uses the Windows NVIDIA driver, which is mapped into Linux for you. The CUDA on WSL guide is blunt about the one mistake that breaks it: do not install any NVIDIA Linux driver inside WSL, because it overwrites the mapped one.
- Install or update the NVIDIA driver on Windows.
- Update WSL from PowerShell:
wsl.exe --update. - Inside WSL, run
nvidia-smi(it has fewer features on WSL, but it should list the GPU). - Install the CUDA build of PyTorch inside WSL with the selector’s Linux command.
If you already installed a Linux NVIDIA driver package in WSL, remove it, then restart WSL with wsl --shutdown.
CUDA not available in Docker
A container sees no GPU unless the host passes it through. On Linux, install the NVIDIA Container Toolkit, configure Docker for it, and start containers with --gpus:
sudo nvidia-ctk runtime configure --runtime=docker # edits /etc/docker/daemon.json
sudo systemctl restart docker
docker run --rm --gpus all IMAGE nvidia-smi
The image also needs a CUDA build of PyTorch inside it. For Compose files, our Ollama Docker GPU setup shows the deploy.resources block that does the same as --gpus all.
Hidden GPUs and “No CUDA GPUs are available”
“RuntimeError: No CUDA GPUs are available” means PyTorch has CUDA support but sees zero devices. If nvidia-smi lists your card, check CUDA_VISIBLE_DEVICES. An empty value, -1, or a number for a GPU you don’t have hides every card. Some notebooks and job scripts set it at the top; unset it or set it to 0.
unset CUDA_VISIBLE_DEVICES # Linux / macOS / WSL
Remove-Item Env:CUDA_VISIBLE_DEVICES # Windows PowerShell
Macs, AMD GPUs and very old cards
| Your machine | What to install | How to check |
|---|---|---|
| Mac (Apple silicon) | The standard macOS PyTorch; there is no CUDA on a Mac | torch.backends.mps.is_available(), then use device="mps" |
| AMD GPU on Linux | The ROCm build from the PyTorch selector | torch.cuda.is_available(): the ROCm build answers through the same functions |
| Very old or very new NVIDIA card | A PyTorch build that supports your GPU generation | If you see “no kernel image is available for execution on the device”, the build has no code for your card |
The MPS backend notes also explain how to tell a PyTorch built without MPS from a Mac that can’t use it.
Once the GPU is available, the next error most people meet is running out of its memory: see our CUDA out of memory fixes, and size models first with the VRAM calculator.
A one-file check you can rerun
Save this as gpucheck.py and run it with the same Python that runs your project. It prints every link in the chain, so you can paste the output when you ask for help:
import os, sys, torch
print("python ", sys.executable)
print("torch ", torch.__version__, "from", torch.__file__)
print("built for ", "CUDA", torch.version.cuda)
print("visible env ", os.environ.get("CUDA_VISIBLE_DEVICES", "(not set)"))
print("available ", torch.cuda.is_available())
if torch.cuda.is_available():
print("devices ", torch.cuda.device_count())
print("first GPU ", torch.cuda.get_device_name(0))
print("cuDNN ", torch.backends.cudnn.version())
Read it top to bottom. A None next to “built for” is the CPU-only build. “available False” with a CUDA number above it points to the driver or a hidden GPU. A device count of zero with the variable set points straight at CUDA_VISIBLE_DEVICES. Run it again after every fix, so you know which change worked.
Jake’s checklist
nvidia-smiworks? If not, fix the driver and reboot.torch.version.cudaprints a number? If not, uninstall and reinstall the CUDA build.- Its CUDA version is no newer than the one
nvidia-smishows? If it is, update the driver. - Same Python everywhere? Check
sys.executablein the terminal, IDE and notebook. - WSL: Windows driver only. Docker: Container Toolkit and
--gpus all. CUDA_VISIBLE_DEVICESunset or pointing at a real GPU.
Jake: "Four minutes a batch, and now?"
Ethan: "Eleven seconds. Same card, same script, the right PyTorch."
Jake: "I’ll write that install line on the wall."
Ethan: "Write the check too. torch.version.cuda takes one second and saves a morning."
Official references for this guide
- PyTorch: Start Locally: the install selector, CPU versus CUDA and ROCm builds, and the
torch.cuda.is_available()check. - NVIDIA CUDA on WSL User Guide: install only the Windows driver; never a Linux NVIDIA driver inside WSL.
- NVIDIA Container Toolkit installation:
nvidia-ctk runtime configurefor Docker. - PyTorch MPS backend: GPU acceleration on Apple-silicon Macs.
Frequently asked questions
Why does torch.cuda.is_available() return False?
Usually because PyTorch was installed without CUDA (torch.version.cuda prints None), or the NVIDIA driver isn't working (nvidia-smi fails). Less often, CUDA_VISIBLE_DEVICES hides the GPU, or you're in WSL or Docker without GPU access.
How do I fix "Torch not compiled with CUDA enabled"?
You have the CPU-only build of PyTorch. Uninstall torch, torchvision and torchaudio, then reinstall with the command from the PyTorch install selector for your CUDA version, which adds --index-url https://download.pytorch.org/whl/cuXXX.
Does pip install torch include CUDA on Windows?
No. On Windows, plain pip install torch gives the CPU-only build. The CUDA build comes from PyTorch's own package index, so use the command the install selector gives for your CUDA version.
Do I need to install the CUDA Toolkit for PyTorch?
No. The pip and conda builds of PyTorch carry their own CUDA libraries. You need an NVIDIA driver new enough for the CUDA version you picked; the toolkit is only for compiling your own CUDA code.
What does the CUDA Version in nvidia-smi mean?
It is the newest CUDA version your driver can run, not a CUDA installation. Any PyTorch build for that CUDA version or older works with the driver.
How do I fix "NVIDIA-SMI has failed because it couldn't communicate with the NVIDIA driver"?
The driver isn't loaded. On Linux the usual causes are a kernel update the driver module wasn't rebuilt for, Secure Boot blocking the unsigned module, or the open nouveau driver in the way. Reinstall the driver for the running kernel and reboot.
Why is CUDA not available in WSL?
WSL uses the Windows NVIDIA driver, mapped into Linux. Install or update the driver on Windows, run wsl --update, and never install a Linux NVIDIA driver inside WSL: it overwrites the mapped one.
Why is CUDA not available inside Docker?
Containers don't see the GPU unless the host has the NVIDIA Container Toolkit, Docker is configured for it with nvidia-ctk runtime configure --runtime=docker, and you start the container with --gpus all.
What does "RuntimeError: No CUDA GPUs are available" mean?
PyTorch has CUDA support but can't see a GPU. Check that nvidia-smi lists one, and that CUDA_VISIBLE_DEVICES isn't empty or pointing at a GPU number that doesn't exist.
Can I use CUDA on a Mac?
No. Macs have no NVIDIA GPU support for CUDA. On Apple silicon, PyTorch uses the mps device instead; check it with torch.backends.mps.is_available().
Does torch.cuda.is_available() work with AMD GPUs?
Yes, with the ROCm build of PyTorch on Linux. It uses the same torch.cuda functions, so is_available() returns True when the AMD GPU is set up correctly.
Why does nvidia-smi work but torch.cuda.is_available() is False?
The driver is fine, so the problem is PyTorch: almost always the CPU-only build, or a different Python environment than the one you installed the CUDA build into. Print torch.__file__ and torch.version.cuda to check both.
How do I check which PyTorch build I have?
Run python -c "import torch; print(torch.__version__, torch.version.cuda)". A version ending in +cpu, or None for the CUDA version, means the CPU-only build.
What does "no kernel image is available for execution on the device" mean?
CUDA works, but this PyTorch build has no code for your GPU's generation: the card is too old or too new for it. Pick a PyTorch build that supports your GPU.
Why is CUDA not available after a Windows or driver update?
An update can replace the NVIDIA driver with an older or generic one. Reinstall the current driver from NVIDIA, reboot, and check nvidia-smi again.
Is CUDA not available the same as CUDA out of memory?
No. Not available means PyTorch can't use the GPU at all. Out of memory means it can, but the job didn't fit in VRAM; that has different fixes.
Revision note. Written November 27, 2026, for current PyTorch builds and NVIDIA drivers. “A chain is only as strong as its weakest link”: test each link, driver to Python, in order.