Error database

torch.cuda.is_available() returns False

PyTorch cannot see your GPU. Check whether you installed the CPU-only wheel first, because that is the cause most of the time.

The message you saw
torch.cuda.is_available() returns False

By Updated

The error

Output
>>> import torch
>>> torch.cuda.is_available()
False

Or, when something in your code goes ahead and tries anyway:

Output
AssertionError: Torch not compiled with CUDA enabled
Output
RuntimeError: Found no NVIDIA driver on your system. Please check that you have an NVIDIA GPU and installed a driver from http://www.nvidia.com/Download/index.aspx

What it means

PyTorch looked for a usable NVIDIA GPU and did not find one. Three separate things must all be in place for it to succeed: a physical NVIDIA GPU, a working NVIDIA driver, and a build of PyTorch that contains CUDA support. Any one missing gives you False.

The second message, Torch not compiled with CUDA enabled, is more specific and more useful. It says the PyTorch you installed is the CPU-only build. No driver fix will change it.

Why it happens

The most frequent cause by a wide margin is installing the CPU wheel. pip install torch from the default PyPI index gives you a CPU-only build on Linux, and it does so without any warning, because it is a legitimate package that a great many people want. Your code then runs, slowly, on the CPU.

The second cause is a driver that is missing, too old, or not visible. PyTorch's wheels bundle the CUDA runtime, so you do not need a system CUDA toolkit installed. You do still need the NVIDIA kernel driver. It must be new enough for the CUDA version the wheel was built against.

After that: no NVIDIA GPU at all (an Apple Mac, an AMD card, laptop integrated graphics); a container started without GPU access; CUDA_VISIBLE_DEVICES set to an empty string or to a device index that does not exist; a cloud notebook whose runtime type is set to CPU; or a WSL2 setup where a Linux driver was installed inside WSL instead of a Windows driver on the host.

How to fix it

1. Ask PyTorch what build you have. This is the first check and it resolves most cases in ten seconds.

python
import torch
print(torch.__version__)        # 2.5.1+cpu  → CPU-only build
print(torch.version.cuda)       # None       → CPU-only build
print(torch.cuda.is_available())
print(torch.cuda.device_count())

A +cpu suffix, or torch.version.cuda printing None, is a definite answer: the wheel has no CUDA in it. Reinstall the CUDA build:

bash
python -m pip uninstall -y torch torchvision torchaudio
python -m pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu124

Take the exact URL from the selector at pytorch.org rather than copying cu124 blindly — the tag changes with each release, and it must be a version your driver supports.

2. Check that the system itself can see the GPU.

bash
nvidia-smi

If this prints a table with your GPU and a driver version, the hardware and driver are fine and the problem is on the PyTorch side, so go back to step 1. If it prints command not found or NVIDIA-SMI has failed because it couldn't communicate with the NVIDIA driver, PyTorch is not the problem — install or repair the driver from NVIDIA's site and reboot.

3. Check the driver is new enough. The driver version is in the top-left of the nvidia-smi output. A driver older than the CUDA runtime in your wheel will fail even though both exist. If your driver is old and you cannot update it, install a PyTorch build for an older CUDA version instead. You do not need to install the CUDA Toolkit separately for PyTorch — that is only needed if you compile CUDA extensions yourself.

4. Look for an environment variable hiding the GPU.

bash
echo $CUDA_VISIBLE_DEVICES     # empty output is fine; an empty string or -1 is not
unset CUDA_VISIBLE_DEVICES
powershell
$env:CUDA_VISIBLE_DEVICES      # Windows

Some cluster schedulers and Docker images set this. CUDA_VISIBLE_DEVICES="" hides every GPU, and setting it to 1 on a single-GPU machine hides the only one you have.

5. Match the fix to your platform.

Google Colab or Kaggle: Runtime → Change runtime type → select a GPU accelerator, then run the cell again. A CPU runtime is the default in Colab.

Docker: the container needs the NVIDIA Container Toolkit on the host and the GPU flag at run time.

bash
docker run --gpus all -it pytorch/pytorch:latest nvidia-smi

WSL2: install the NVIDIA driver on Windows, not inside the Linux distribution. Installing a Linux driver in WSL breaks the passthrough. nvidia-smi inside WSL should work once the Windows driver is correct.

Laptop with switchable graphics: confirm in the NVIDIA Control Panel that the discrete GPU is enabled and not disabled in BIOS.

6. On a Mac, stop looking for CUDA. Apple Silicon has no NVIDIA hardware and never will. The GPU backend is called MPS:

python
device = "mps" if torch.backends.mps.is_available() else "cpu"
x = torch.randn(3, 3, device=device)

Most models run on MPS; a few operations still fall back to the CPU, which PYTORCH_ENABLE_MPS_FALLBACK=1 allows.

How to prevent it

Write the device check into your script instead of assuming, and make it loud when the GPU is missing so you find out in the first second rather than after an hour of slow training:

python
import torch

if torch.cuda.is_available():
    device = torch.device("cuda")
    print(f"GPU: {torch.cuda.get_device_name(0)}  |  CUDA {torch.version.cuda}")
elif torch.backends.mps.is_available():
    device = torch.device("mps")
    print("Apple MPS backend")
else:
    device = torch.device("cpu")
    print("WARNING: running on CPU — training will be slow")

Record the install command in your README with the exact index URL for the machine, so the next person does not fall into the default CPU wheel. And when you set up a new environment, run nvidia-smi and the four-line check above before installing anything else — a broken GPU setup found at the start costs minutes, and found at 2am costs a night.