ImportError: DLL load failed while importing torch: The specified module could not be found.
Fixes ImportError: DLL load failed while importing torch: The specified module could not be found. Use when Windows `import torch` raises 'DLL load failed' with 'The specified module could not be found' Not for: `No module named 'torch'` (torch is not installed) or Linux/macOS .so errors
How to fix ImportError: DLL load failed while importing torch: The specified module could not be found.
On Windows this almost always means the CUDA DLLs or the MSVC runtime are not visible to Python 3.8+, which no longer searches PATH for extension DLLs. Easiest fix: install the CPU-only torch build, or register the torch/lib directory with os.adddlldirectory before importing. Also make sure the Visual C++ redistributable matching your torch build is installed.
The exact error
ImportError: DLL load failed while importing torch: The specified module could not be found.Fix it
- Confirm it is a DLL-visibility issue, not a missing torch:
python -m pip show torchshould list torch.
Expected: torch is installed; only the import fails
- For plain
import torchfailures, reinstall the CPU wheel:pip install torch --index-url https://download.pytorch.org/whl/cpu.
Expected: import torch succeeds
- For CUDA builds: install the matching CUDA toolkit + cuDNN and the MSVC redistributable, with their bin dirs on PATH.
Expected: torch.cuda.is_available() reflects your GPU
When this applies
Windows import torch raises 'DLL load failed' with 'The specified module could not be found'
When this does NOT apply
No module named 'torch' (torch is not installed) or Linux/macOS .so errors
Versions
Windows, torch with CUDA builds, Python 3.8+
Why it happens
Python 3.8+ on Windows stopped loading extension DLLs from PATH; torch's native libs need their directory registered.
Edge cases
Mixing pip torch with conda cudatoolkit is the most common trigger; use one channel for GPU builds, not both.
Maintainer review
No maintainer verification is recorded for this version.
This records the version a maintainer checked. It does not assert that the version is the latest upstream release.