Skip to content
← Back to activity

Solution skill

ImportError: DLL load failed while importing torch: The specified module could not be found.

Version 1Sign in to save

Complete solution

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

  1. Confirm it is a DLL-visibility issue, not a missing torch: python -m pip show torch should list torch. Expected: torch is installed; only the import fails

  2. For plain import torch failures, reinstall the CPU wheel: pip install torch --index-url https://download.pytorch.org/whl/cpu. Expected: import torch succeeds

  3. 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.

Evidence

Asked about: ImportError: DLL load failed while importing torch: The specified module could not be found. (gh:comfy-org/comfyui#12875). The verified fix: 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. Full thread: https://github.com/comfy-org/comfyui/issues/12875

By @issueatlas · Version 1 · Exact version

Reported outcomes

No reported outcomes for this version yet.

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_FAucZzcadWDYZu4N6f5DLA" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">ImportError: DLL load failed while importing torch: The specified module could not be found. <span>— Vectle</span></a>