Free | No tracking | Every fact with a source|German and English

Error / Installation

OSError: CUDA_HOME environment variable is not set (CUDA toolkit with nvcc is missing during compilation)

A package wants to compile its own CUDA code during installation and can’t find the CUDA compiler nvcc.

The message

OSError: CUDA_HOME environment variable is not set. Please set it to your CUDA install root. (vorher oft: UserWarning: CUDA was not found on the system, please set the CUDA_HOME or the CUDA_PATH environment variable or add NVCC to your system PATH. The extension compilation will fail.)

Affects: Python

Why is this happening?

Some packages and extensions build their own CUDA components during pip install. For that, you need the CUDA toolkit with the compiler nvcc — neither the graphics driver nor PyTorch includes it. PyTorch looks for the toolkit via the CUDA_HOME or CUDA_PATH variables, then via nvcc in PATH, and on Windows lastly in the C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA folder. If it finds nothing, this error appears.

How to fix it

  1. Check in a terminal with nvcc -V whether the CUDA toolkit is installed. If it says “not recognized,” it’s missing.
  2. Find out which CUDA version your PyTorch was built with: python -c "import torch; print(torch.version.cuda)" (in your venv).
  3. Install the CUDA toolkit with the same major version from developer.nvidia.com/cuda-toolkit-archive. By default, the installer places it under C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\vX.Y and sets the CUDA_PATH variable.
  4. Close all terminals and open a new one. If that doesn’t work, set the variable yourself, for example in PowerShell $env:CUDA_HOME="C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.8" (adjust the version), on Linux export CUDA_HOME=/usr/local/cuda.
  5. Test: python -c "import torch; from torch.utils.cpp_extension import CUDA_HOME; print(torch.cuda.is_available(), CUDA_HOME)" must show True and a CUDA folder.
  6. On Windows, you also need Visual Studio or the C++ Build Tools to compile (see the entry “Microsoft Visual C++ 14.0 or greater is required”).
  7. If you still get the error even though the variable is set correctly, add --no-build-isolation to the pip command, for example pip install --no-build-isolation -e ..

Better not: Don’t install just any CUDA toolkit version: if the major version differs from your PyTorch version, the build will fail with a “mismatches the version” message.

Terms for this

Similar errors

Sources

Checked on Oct 27, 2026. Didn't help? Ask in the forum and name the graphics card, program, and the full message.