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
- Check in a terminal with
nvcc -Vwhether the CUDA toolkit is installed. If it says “not recognized,” it’s missing. - Find out which CUDA version your PyTorch was built with:
python -c "import torch; print(torch.version.cuda)"(in your venv). - 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.Yand sets the CUDA_PATH variable. - 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 Linuxexport CUDA_HOME=/usr/local/cuda. - Test:
python -c "import torch; from torch.utils.cpp_extension import CUDA_HOME; print(torch.cuda.is_available(), CUDA_HOME)"must showTrueand a CUDA folder. - 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”).
- If you still get the error even though the variable is set correctly, add
--no-build-isolationto the pip command, for examplepip 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
- A1111: INCOMPATIBLE PYTHON VERSION / Couldn't install torch
- module 'torch' has no attribute 'float8_e4m3fn' (PyTorch too old for fp8)
- No matching distribution found for torch (wrong Python version)
- No module named 'triton' on Windows (triton-windows missing)
- Transformers: FlashAttention2 has been toggled on, but … flash_attn seems to be not installed (FlashAttention missing)
Sources
- https://github.com/pytorch/pytorch/blob/main/torch/utils/cpp_extension.py
- https://github.com/IDEA-Research/Grounded-SAM-2/blob/main/INSTALL.md
- https://docs.nvidia.com/cuda/cuda-installation-guide-microsoft-windows/index.html
Checked on Oct 27, 2026. Didn't help? Ask in the forum and name the graphics card, program, and the full message.