How to Fix CUDA and C++ Build Errors for Python AI Apps on Windows
By Furkan Gözükara · Updated Nov 21, 2026
To fix CUDA and C++ build errors in Python AI apps on Windows, install Visual Studio Community 2022 with its C++ tools, put the MSVC compiler folder on PATH, install CUDA 13.1 and 12.9.1 with cuDNN, and keep Python, FFmpeg and Git in a clean PATH order. Most failed builds of InsightFace, Flash Attention, xFormers or a torch.compile run trace back to one of these pieces being missing or found in the wrong version. The steps below follow the public CUDA and C++ tools fix guide for AI apps, last updated on 11 July 2026.
Why Python AI apps fail to build on Windows
Many AI libraries contain CUDA code. When pip finds no ready wheel for your Python, Torch and CUDA versions, it compiles the library on your PC, and that build needs the MSVC C++ compiler (cl), the CUDA compiler (nvcc) and the right libraries on PATH at the same time. As the pre-compiled wheels post explains, such libraries take a long time to compile or fail in most cases unless the CUDA archs and the Torch, CUDA and Python versions all match.
| Error you see | Usual cause | Fix below |
|---|---|---|
| Microsoft Visual C++ 14.0 or greater is required | No C++ build tools | Visual Studio Community 2022 |
| cannot open include file: 'stdio.h' (InsightFace build) | Missing C++ components | Reinstall Visual Studio with all components |
cl is not recognized | MSVC folder not on PATH | Add the Hostx64\x64 folder |
nvcc missing or wrong version | CUDA missing or PATH order | CUDA 13.1 and 12.9.1, then restart |
| CUDA_PATH is set but CUDA wasn't able to be loaded (onnxruntime) | The CUDA or cuDNN version the app expects is missing | cuDNN and its PATH folders |
| Triton related errors | Stale Triton cache | Clear the .triton folder |
| Random, unexplained failures | Non-English characters or spaces in user name or paths | English-only paths, long paths on |
Manual setup with the July 2026 versions
1. Visual Studio Community 2022 and the MSVC compiler
- Visual Studio Build Tools are no longer needed. Uninstall existing Build Tools and Visual Studio Community installs, then do a fresh install of Visual Studio Community 2022.
- Run the installer as administrator and select all checkboxes. The guide uses Visual Studio 17.14.35; newer versions work too. A 2026 edition may use different folder names, so 2022 is recommended for now.
- Add the compiler folder to both the System and the User Path, for example
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207\bin\Hostx64\x64, using the newest version folder you have. - Open a new PowerShell window (not cmd) and type
cl. If the compiler answers, C++ builds can find it.
2. CUDA 13.1 and CUDA 12.9.1 side by side
- Install CUDA 12.9.1 for Windows 10 or 11.
- Install CUDA 13.1, now the preferred version, with Custom (Advanced) and without changing any selections.
- Restart the PC, open a terminal and run
nvcc --versionto confirm.
3. cuDNN 9.19 and CUDNN_PATH
- Install cuDNN 9.19 with the default options; it goes into
C:\Program Files\NVIDIA\CUDNN. - Add three folders to both Paths:
C:\Program Files\NVIDIA\CUDNN\v9.19\bin\12.9\x64,C:\Program Files\NVIDIA\CUDNN\v9.19\bin\13.1\x64andC:\Program Files\NVIDIA\CUDNN\v9.19. - Create the system variable
CUDNN_PATHwith the valueC:\Program Files\NVIDIA\CUDNN\v9.19\bin. This extra variable is easy to forget.
4. Python 3.10, 3.11, 3.12 and 3.13
Install all four: 3.10.11, 3.11.9, 3.12.10 (the preferred version) and 3.13.14 (the least supported right now). Install them directly into the C drive with the Python Launcher and select every option; pip, tcl/tk and the py launcher are mandatory. Keep Python 3.10.11 at the top of both Paths, because older apps may still use your default Python. The SECourses apps create their own virtual environment with the right version.
5. FFmpeg, Git, Node.js and TensorRT
- FFmpeg: the guide's
Install_FFmpeg_Latest.bat(right-click, run as administrator) puts FFmpeg 9 static intoC:\ffmpeg_latestand FFmpeg 8.1 shared intoC:\ffmpeg_latest\lib, then sets both Paths. TorchAudio and TorchCodec need the shared DLLs, and so do builds that compile against FFmpeg. - Git: add
C:\Program Files\Git\cmdandC:\Program Files\Git\binto both Paths. - Node.js 22.20: some apps, such as Ostris AI Toolkit, need it.
- TensorRT 10.13.2 GA: needed in some cases. Extract it to
C:\TensorRT_10_13_2_6, check that itslibfolder containsnvinfer_10.dll, and add both thelibfolder and the root folder to both Paths.
6. Windows settings that cause hidden failures
- Set at least 100 GB of virtual memory on your fastest drive, because loading a model can use it.
- Enable Windows long paths; the guide includes a ready
.regfile. - Never use non-English characters in your Windows user name, and avoid non-English characters and spaces in folder paths.
PATH order decides which version wins
Every folder above goes into both the System and the User Path, and the top-to-bottom order matters: Windows uses the first match. If an old CUDA, Python or FFmpeg sits higher in the list, a build picks it up even though the new one is installed. The fix guide includes screenshots of the system variables and both Path lists to compare against. After changing PATH, open a new terminal before testing.
Fixing Triton errors
If torch.compile or Triton throws errors, clear the Triton cache folder at C:\Users\<your user name>\.triton. The guide provides Clear_Triton_Cache.zip with a bat file for this: extract it anywhere and double-click the bat file, without running it as administrator.
Skip compiling with pre-compiled wheels
Sometimes the fastest fix is not to compile at all. The pre-compiled Flash Attention and xFormers wheels post, available to members on Patreon, includes Flash Attention 2.8.4 for Torch 2.11 and CUDA 13 and xFormers 0.0.35 for Windows and Linux. The Windows Flash Attention wheel alone took over 7 hours to compile on an AMD 9950X.
A wheel only works on the GPUs it was built for, by compute capability:
- 8.6 (sm_86): RTX 30 series and cards such as the RTX A6000
- 8.9 (sm_89): RTX 40 series, L4, L40S and RTX 6000 Ada
- 12.0 (sm_120): RTX 50 series and RTX PRO Blackwell cards
Here 12.0 means compute capability, not CUDA 12.0. A native sm_86 binary also runs on 8.9 GPUs but not on 8.0 or 9.0, while a build with +PTX can be JIT-compiled for newer GPUs. On Windows, very large wheels do not work, so server GPUs are left out of the Windows builds.
Or let one installer do all of this
If you would rather not edit PATH by hand, the 1-click AI Requirements Installer sets up the same kind of stack on Windows and Ubuntu and tests it. See the AI requirements installer guide and the full installer tutorial.
Still failing? Send the logs
Installation logs are mandatory when you report an install error, because they show the real cause. The installation logs post links the video steps for exporting them and shows how to move the Hugging Face cache folder, where many apps download their models.
FAQ
Do I still need Visual Studio Build Tools?
No. Since the July 2026 update, the manual route only needs Visual Studio Community 2022 with all components selected. The guide recommends uninstalling old Build Tools first and doing a fresh Community install.
Which CUDA version should I install for AI apps?
Install both CUDA 13.1 and 12.9.1. CUDA 13.1 is now the default, and the SECourses apps are moving to CUDA 13 and Python 3.12. Restart after installing and confirm with nvcc --version.
Which Python version is best?
Python 3.12.10 is the preferred version, but keep 3.10.11, 3.11.9 and 3.13.14 installed too, because some apps and libraries still require them. Keep 3.10.11 at the top of PATH for older apps.
Why do cl or nvcc still not work after installing?
Usually the folder is missing from one of the two Paths, or the terminal was opened before the change. Add the MSVC Hostx64\x64 folder to both Paths, restart after the CUDA install and open a new PowerShell window.
Is the 2024 setup video still valid?
The Windows AI setup video shows the same method, but its suggested versions (Python 3.10.11, CUDA 12.4, cuDNN 8.9) date from September 2024. Use the versions in the fix guide, which is kept up to date.