The error “AssertionError: Torch not compiled with CUDA enabled” means the copy of PyTorch installed in your Python environment is a CPU-only build, so any call that asks for a GPU, such as .cuda() or a device set to “cuda”, fails immediately. The fix is almost always to uninstall that build and install a PyTorch wheel built for CUDA, using the command generated by the selector on the official PyTorch Get Started page.
The message does not say your NVIDIA card is broken or missing. It says the software package was built without GPU support. Before you reinstall anything, it helps to confirm which build you have, which driver you are running, and which Python environment is actually executing your script, because those three checks explain nearly every case.
What the error actually means
PyTorch ships in several flavors. A CPU-only wheel contains no CUDA kernels at all. A CUDA wheel bundles the CUDA runtime libraries it needs and talks to the NVIDIA driver on your system. When code calls a CUDA function inside a CPU-only wheel, PyTorch raises an assertion with the exact message above.
This commonly happens for a few reasons. A plain “pip install torch” on some platforms pulls the CPU build by default. Another package in your requirements file may have installed torch as a dependency and replaced a working CUDA build. Or a virtual environment, conda environment, or notebook kernel is using a different Python than the one you configured.
Confirm what you have installed
Open a terminal in the same environment that runs your script and start Python. Then check these values; each answers a different question.
- torch.__version__ prints the version string. A suffix such as “+cpu” is a strong sign of a CPU-only build, while a suffix that names a CUDA release indicates a GPU build.
- torch.version.cuda prints the CUDA version the wheel was built against. If it prints None, the build has no CUDA support.
- torch.cuda.is_available() returns True only when a CUDA build, a compatible driver, and a visible GPU are all present.
- torch.cuda.device_count() shows how many GPUs PyTorch can see, which helps when the answer to the previous check is False.
Also run “nvidia-smi” in a normal terminal. If it lists your GPU and a driver version, the hardware and driver are working and the problem is purely the PyTorch package. If nvidia-smi is not recognized or reports an error, fix the driver first.
Step-by-step fix
1. Make sure the driver is current enough
The CUDA wheels from PyTorch carry their own CUDA runtime, so you generally do not need to install the separate CUDA Toolkit just to run PyTorch. You do need an NVIDIA driver new enough for that runtime. The top-right of the nvidia-smi output shows the highest CUDA version your driver supports; the wheel you choose should not target a newer CUDA version than that. If it does, update the driver from the NVIDIA app or the official driver download page.
2. Uninstall the CPU build completely
In the affected environment, run “pip uninstall torch torchvision torchaudio” and repeat it until pip says the packages are not installed. Leftover copies are a frequent reason the old build keeps loading. If you use conda, remove the same packages with conda instead, and avoid mixing pip and conda installs of torch in a single environment.
3. Install the CUDA build from the official selector
On the PyTorch Get Started page, choose your operating system, the pip or conda package manager, Python as the language, and a CUDA compute platform. The page then shows a ready-made command, which for pip normally includes an extra index address so that pip downloads the CUDA wheel rather than the default one. Copy that command exactly. Because the available CUDA options change from release to release, check the current selector instead of reusing an old command from a forum post.
4. Verify inside Python
Run the checks from the earlier section again. torch.version.cuda should now show a version number and torch.cuda.is_available() should return True. You can also print torch.cuda.get_device_name(0) to confirm it names your GeForce card.
Symptom, cause and fix at a glance
| What you see | Likely cause | Fix |
|---|---|---|
| Version string ends in “+cpu” | CPU-only wheel installed | Uninstall and reinstall using the CUDA command from the selector |
| torch.version.cuda is None | Build has no CUDA support | Same as above |
| CUDA build installed but is_available() is False | Driver too old, missing, or GPU not visible | Update the NVIDIA driver and confirm nvidia-smi lists the card |
| Fix works in terminal, fails in notebook | Notebook kernel uses a different Python | Select the correct kernel or install into the kernel’s environment |
| Error returns after installing another package | Dependency replaced torch with a CPU build | Reinstall torch last, or pin the version in your requirements |
| No NVIDIA GPU present | Machine has AMD, Intel, or Apple graphics only | Use the CPU path or a backend that matches the hardware |
Check you are fixing the right environment
Many people reinstall correctly and still see the error because the script runs somewhere else. Print sys.executable inside the failing script or notebook and compare it with the Python you used for the install. On Windows, the commands “where python” and “where pip” list every interpreter on your path; on Linux or macOS use “which”. Running “python -m pip install” instead of bare “pip install” ties the install to the interpreter you named, which avoids a surprising number of mismatches.
IDEs add another layer. Visual Studio Code, PyCharm, and Jupyter each store their own interpreter selection per project. If you created a new virtual environment, point the IDE at it explicitly. Terminals inside the IDE may activate one environment while the run button uses another.
Fix the code, not only the install
Even with a correct install, hard-coded GPU calls make a script fragile on machines without CUDA. A safer pattern is to choose the device once, for example device = torch.device(“cuda” if torch.cuda.is_available() else “cpu”), and then move models and tensors with .to(device). That way the same script runs on a laptop without an NVIDIA GPU and on a desktop with one, and a failed GPU setup produces a clear slowdown instead of a crash.
Many open-source projects, such as image generators and language model tools, also include a command-line flag or setting to force CPU mode or to select a device. If a project bundles its own virtual environment, reinstall torch inside that environment using the project’s documented method, since its launcher may reinstall the wrong build each time it starts.
When a reinstall still does not help
- Unsupported Python version. Brand-new Python releases sometimes lack prebuilt PyTorch wheels, so pip silently picks something else or fails. Check the supported versions in the current PyTorch documentation and create an environment with a supported one.
- 32-bit Python. PyTorch needs a 64-bit interpreter.
- Older GPUs. Very old GeForce cards may fall below the minimum compute capability that current wheels support. The warning message usually names the capability, and the older GPU may need an older PyTorch release.
- Laptops with hybrid graphics. Make sure the NVIDIA GPU is active and the driver is installed, not only the integrated graphics driver.
- Remote or container setups. In Docker or WSL, the GPU must be exposed to the environment, and the NVIDIA driver on the host must support that path. Check the current NVIDIA container and WSL documentation for the required steps.
If you reach this point, copy the full output of nvidia-smi and the Python checks into a bug report for the project; those lines give maintainers what they need.
Related guides
- What Does Manage Gpu Performance Counters Mean On Nvidia Hardware
- Low Profile Nvidia Graphics Cards For Small Form Factor Pcs
- Nvidia App Error Your System Configuration Is Not Supported
Frequently Asked Questions
Do I need to install the CUDA Toolkit to fix this error?
Usually not. The PyTorch CUDA wheels include the CUDA runtime libraries they need, so a compatible NVIDIA driver is generally enough. The full toolkit matters when you compile custom CUDA extensions yourself.
Why does nvidia-smi show a CUDA version different from the one in PyTorch?
The version in nvidia-smi is the highest CUDA version the driver supports, while torch.version.cuda is the version the wheel was built with. They do not have to match, as long as the driver supports at least what the wheel needs.
Can I run PyTorch without an NVIDIA GPU?
Yes. The CPU build works for learning and small models, just more slowly. Some backends exist for other hardware, but availability changes, so check the current PyTorch documentation for your platform.
Will reinstalling PyTorch delete my projects?
No. Uninstalling the packages only removes the libraries from that Python environment, not your scripts or data. If you want extra safety, export your package list with pip freeze before you begin so you can restore other dependencies.
Write Your Review
No reviews yet. Be the first to share your experience!