No module named 'torch' in ComfyUI
Fix ModuleNotFoundError: No module named 'torch' in ComfyUI portable, venv, and managed installs, then verify the repaired Torch build still has CUDA.
ComfyUI stops with ModuleNotFoundError: No module named 'torch' (also seen as No module named torch / ComfyUI torch missing) when the Python that launched ComfyUI cannot import Torch. This is a core runtime failure, not a warning.
Fix it by installing a CUDA wheel into that exact Python, then verifying the build is not CPU-only.
.\python_embeded\python.exe -s -m pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cuXXXReplace cuXXX with the CUDA wheel tag for your supported PyTorch build from the official PyTorch selector. Then confirm torch.version.cuda is not None and torch.cuda.is_available() is True before relaunching.
Triage
| What you see | Meaning | First action |
|---|---|---|
ModuleNotFoundError: No module named 'torch' | Torch is missing from the Python that launched ComfyUI | Install Torch in the active ComfyUI Python |
pip show torch works in system Python but ComfyUI still fails | Installed into the wrong Python | Use python_embeded\python.exe or the active venv |
import torch works, but the version ends in +cpu | You repaired the import with a CPU-only wheel | Replace it with a matching CUDA wheel |
Next error becomes No module named 'torchvision' / 'torchaudio' | Adjacent core packages are still missing | Repair those next in the same environment |
torch.cuda.is_available() is False | GPU build mismatch, wrong wheel, or driver problem | Go to the CUDA verification step |
AssertionError: Torch not compiled with CUDA enabled | Installed, but CPU-only or wrong CUDA build | Torch not compiled with CUDA enabled |
Step 1: Use the Python that actually starts ComfyUI
For Windows portable:
.\python_embeded\python.exe -s -c "import sys; print(sys.executable)"
.\python_embeded\python.exe -s -m pip show torch torchvision torchaudioFor a manual venv:
.\venv\Scripts\activate
python -c "import sys; print(sys.executable)"
python -m pip show torch torchvision torchaudioFor ComfyUI Desktop or another managed launcher, use the app's own terminal or environment tools. Do not assume python_embeded exists.
Step 2: Install Torch in the active environment
Choose the CUDA wheel for your GPU, driver, Python version, and supported PyTorch build from the official PyTorch selector. Do not begin with a bare pip install torch: it can restore the import with a CPU-only wheel.
For Windows portable, run the selected command through the embedded Python:
.\python_embeded\python.exe -s -m pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cuXXXFor a manual venv, activate it first, then use the same --index-url pattern with python -m pip. Replace cuXXX with the CUDA wheel tag for your supported build.
Step 3: Verify you did not install CPU Torch
Run this in the same Python that launches ComfyUI:
.\python_embeded\python.exe -s -c "import torch; print(torch.__version__, torch.version.cuda, torch.cuda.is_available()); print(torch.cuda.get_device_name(0) if torch.cuda.is_available() else 'no cuda')"Output ending in +cpu with None False is a CPU-only build. Re-run the Step 2 CUDA-wheel command. Do not add a regional package mirror to the primary command; solve regional network access separately and verify package provenance.
If Torch imports but CUDA still fails, continue with Torch Not Compiled With CUDA Enabled in ComfyUI.
Step 4: Restart and read the next first error
.\python_embeded\python.exe -s ComfyUI\main.py --windows-standalone-buildIn a damaged portable environment the next blocker is often another core package (safetensors, packaging, numpy, torchvision, torchaudio). Fix the next first blocker in the same Python instead of switching to random package commands. If the environment keeps drifting from one core package to another, use the one-package-at-a-time portable repair runbook.
What not to do
- do not install Torch into system Python if ComfyUI launches from
python_embededor a venv - do not assume
import torchsuccess means CUDA is repaired - do not reinstall CUDA Toolkit first for a normal wheel-based ComfyUI setup
- do not start with
pip install -rwhile you are still learning what broke - do not reinstall custom nodes until the core runtime is green again
Related Guides
- Torch Not Compiled With CUDA Enabled in ComfyUI
- Repair ComfyUI Portable Dependencies One Missing Module At A Time
- comfyui-frontend-package is not installed in ComfyUI
- ComfyUI Dependency Conflicts
- Installed Custom Nodes and Broke ComfyUI? Recover Without Reinstalling
Source References
Start free with Wonderful Launcher if this affects your real ComfyUI environment. It keeps launcher-native repair, task logs, and runtime checks in one place; credits are only for image generation and metered tools.
Download Wonderful LauncherSee credit packagesDid this fix your issue?
Your answer helps prioritize verified ComfyUI repairs.