Windows ML Troubleshooting
Diagnose and fix Python ML/AI tool crashes on Windows: CUDA version mismatches, native DLL failures, and environment contamination when calling subprocess Python.
When to use
- Python ML tool crashes with
0xC0000005(access violation) or0xC0000135(DLL not found) torch.cuda.is_available()returnsFalsebutnvidia-smishows a working GPUcudaGetDeviceCount()returnscudaErrorNotSupported- Running a different venv's Python but it loads packages from the wrong environment
1. CUDA / PyTorch Version Mismatch → 0xC0000005 Crash
Symptom: ComfyUI (or any PyTorch app) crashes on startup with:
Windows fatal exception: access violation
Process exited with code 3221225477 / 0xC0000005
Stack (most recent call first):
File "...torch\cuda\__init__.py", line 491 in _lazy_init
And/or:
cudaGetDeviceCount() returned cudaErrorNotSupported, likely using older driver
Root cause: PyTorch was installed with a CUDA build (e.g., cu130) that is
newer than the driver's supported CUDA version. The NVIDIA driver reports
its max CUDA version via nvidia-smi; PyTorch MUST be built with a CUDA version
≤ that number.
Diagnosis:
# Check driver's max CUDA version
nvidia-smi | grep "CUDA Version"
# → "CUDA Version: 12.9" ← this is the MAX allowed
# Check what PyTorch was built with
python -c "import torch; print('CUDA built:', torch.version.cuda)"
# → "CUDA built: 13.0" ← HIGHER than driver → CRASH
Fix: Uninstall and reinstall PyTorch with a compatible CUDA build.
cu124 (CUDA 12.4) is the safest choice for most drivers (CUDA 12.0–12.9):
pip uninstall torch torchvision torchaudio -y
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu124
Verify:
python -c "import torch; print(torch.cuda.is_available(), torch.cuda.get_device_name(0))"
# → "True NVIDIA GeForce GTX 1080 Ti"
CUDA version compatibility table
| Driver CUDA | Safe PyTorch build | Notes |
|---|---|---|
| ≤ 11.8 | cu118 |
Legacy cards |
| 12.0–12.4 | cu121 or cu124 |
cu124 is most stable |
| 12.5–12.9 | cu124 |
cu124 is forward-compatible |
| ≥ 13.0 | cu130 |
Very new drivers only |
2. PYTHONPATH Contamination (Wrong venv Packages Loaded)
Symptom: You call a different venv's Python (e.g., ComfyUI's .venv/Scripts/python.exe),
but it loads packages from the Hermes venv instead.
Root cause: Hermes sets PYTHONPATH, PYTHONHOME, and VIRTUAL_ENV environment
variables that can bleed into subprocess calls and override the target venv's isolation.
Fix: When running Python from a different venv via subprocess.run() or terminal(),
always clear these environment variables first:
import subprocess, os
env = os.environ.copy()
env.pop('PYTHONPATH', None)
env.pop('PYTHONHOME', None)
env.pop('VIRTUAL_ENV', None)
result = subprocess.run(
[r"E:\target\.venv\Scripts\python.exe", "-c", "import torch; print(torch.__file__)"],
capture_output=True, text=True,
env=env
)
Verification: The loaded torch.__file__ should point to the target venv's
site-packages, not the Hermes venv.
3. General DLL Load Failures
Symptom: OSError: [WinError 126] 지정된 모듈을 찾을 수 없습니다 when importing
torch or other native libraries.
Common causes:
- Missing Visual C++ Redistributable (install from https://aka.ms/vs/17/release/vc_redist.x64.exe)
- Missing CUDA toolkit DLLs (check
CUDA_PATHenvironment variable) - cuDNN not in PATH (should be in
CUDA_PATH\bin)
Pitfalls
- Never assume
cu130is safe — many driver versions don't support CUDA 13.0 yet. Always checknvidia-smifirst, then pick the matching PyTorch build. nvidia-smiworking ≠ PyTorch CUDA working — the driver can be healthy but the PyTorch build can still be incompatible. Always verify withtorch.cuda.is_available().- Meta Virtual Monitor (Oculus/Meta Quest) can interfere with CUDA device
enumeration. If
nvidia-smishows the GPU but PyTorch can't see it, the virtual display adapter may be confusing CUDA initialization.