ComfyUI Import Errors: Fix Python Env & CUDA Mismatches
Resolve ComfyUI import failures, onnxruntime-gpu CUDA mismatches, and embedded Python package location issues with verified fixes.
On this page
- TL;DR
- Why ComfyUI imports fail
- Fix 1: Stop packages from installing to the wrong location
- Fix 2: Resolve the onnxruntime-gpu CUDA mismatch (DWPose warning)
- Fix 3: FFMPEG for video nodes
- Verification checklist
- Common errors and fixes
- FAQ
- Decision table: which onnxruntime-gpu to install
- Sources
- Media placeholders
TL;DR
- Isolate ComfyUI's embedded Python — set
PYTHONNOUSERSITE=1and pointPYTHONPATHtopython_embeded\Lib\site-packagesso packages install where ComfyUI can actually find them. - Match onnxruntime-gpu to your PyTorch CUDA version — modern onnxruntime-gpu (1.17+) supports CUDA 12.x natively; downgrading PyTorch to CUDA 11.8 is no longer necessary for most users.
- Use pip.ini to control install location — create
%APPDATA%\pip\pip.iniwith[global] user = falseto stop pip from writing to your user site-packages directory.
Why ComfyUI imports fail
ComfyUI ships with its own embedded Python interpreter. When you run pip install without telling it otherwise, packages land in your user site-packages folder (typically AppData\Roaming\Python\PythonX.Y\site-packages on Windows). ComfyUI's embedded interpreter never looks there, so custom nodes report ModuleNotFoundError or IMPORT FAILED even though the package appears installed.
This is not a ComfyUI bug — it is how Python works. The interpreter only searches paths in sys.path. The user site-packages directory gets added to sys.path automatically unless you disable it with the -s flag or the PYTHONNOUSERSITE environment variable.
Python documentation confirms: "If this is set, Python won't add the user site-packages directory to sys.path." — https://docs.python.org/3/using/cmdline.html
Fix 1: Stop packages from installing to the wrong location
Create a pip.ini file
On Windows, pip reads the per-user config at %APPDATA%\pip\pip.ini. Create it with:
[global]
user = false
pip documentation confirms this location: "Windows User: %APPDATA%\pip\pip.ini" — https://pip.pypa.io/en/stable/topics/configuration/
The user = false setting overrides the default behavior that would otherwise install packages with --user when not in a virtual environment.
Launch ComfyUI with the right environment variables
Save this as start_comfyui.bat in your ComfyUI root directory (where main.py lives):
@echo off
setlocal
set PYTHONNOUSERSITE=1
set PYTHONPATH=%~dp0python_embeded\Lib\site-packages
.\python_embeded\python.exe -s ComfyUI\main.py --windows-standalone-build
endlocal
PYTHONNOUSERSITE=1tells Python to skip the user site-packages directoryPYTHONPATHpoints at the embedded environment's site-packages- The
-sflag on the python command does the same thing asPYTHONNOUSERSITE=1 - Always launch ComfyUI through this batch file
Fix 2: Resolve the onnxruntime-gpu CUDA mismatch (DWPose warning)
What the error means
UserWarning: Onnxruntime not found or doesn't come with acceleration providers,
switch to OpenCV with CPU device. DWPose might run very slowly
This appears when onnxruntime-gpu cannot load its CUDA execution provider. The most common cause: the onnxruntime-gpu package was built for a different CUDA major version than your PyTorch installation.
What changed since 2023
Many guides (including a popular Civitai article from December 2023) state that onnxruntime-gpu only supports CUDA 11.8 and recommend downgrading PyTorch to CUDA 11.8. That advice is stale.
The official ONNX Runtime CUDA Execution Provider documentation shows:
| ORT version | CUDA version | cuDNN | Availability |
|---|---|---|---|
| 1.17.x – 1.26.x | 12.x / 12.8 | 8.x / 9.x | PyPI, NuGet |
| 1.27.x+ | 13.0 | 9.x | PyPI, NuGet (default) |
Source: https://onnxruntime.ai/docs/execution-providers/CUDA-ExecutionProvider.html
Since ORT 1.17 (mid-2023), CUDA 12.x has been supported. Since ORT 1.27 (late 2024), the default pip install onnxruntime-gpu pulls a CUDA 13.0 build.
The compatibility rule
onnxruntime-gpu and PyTorch must share the same major CUDA and cuDNN version for DLL preloading to work. ONNX Runtime 1.21.0+ provides onnxruntime.preload_dlls() to load CUDA/cuDNN DLLs from PyTorch's installation, so you do not need a separate CUDA toolkit install.
Official docs: "The onnxruntime-gpu package is designed to work seamlessly with PyTorch, provided both are built against the same major version of CUDA and cuDNN." — https://onnxruntime.ai/docs/execution-providers/CUDA-ExecutionProvider.html
What to do
| Your PyTorch CUDA | Recommended onnxruntime-gpu | Action | Source |
|---|---|---|---|
| CUDA 12.x (torch 2.x+cu121/124/126/128) | ORT 1.17.x – 1.26.x (CUDA 12.8) | pip install onnxruntime-gpu==1.18.0 or let pip resolve | https://onnxruntime.ai/docs/execution-providers/CUDA-ExecutionProvider.html |
| CUDA 11.8 (torch 2.x+cu118) | ORT 1.18.x or 1.19.x (CUDA 11.8) | pip install onnxruntime-gpu==1.19.0 | https://onnxruntime.ai/docs/execution-providers/CUDA-ExecutionProvider.html |
| CUDA 13.x (torch 2.5+) | ORT 1.27+ (CUDA 13.0) | pip install onnxruntime-gpu (default) | https://onnxruntime.ai/docs/execution-providers/CUDA-ExecutionProvider.html |
Do not downgrade PyTorch to CUDA 11.8 unless you are on an older GPU/driver that requires it. Install the matching onnxruntime-gpu version instead.
For ComfyUI portable users
Use the embedded Python explicitly:
.\python_embeded\python.exe -m pip install onnxruntime-gpu==1.18.0
The portable distribution's Python lives at python_embeded\python.exe — this is the interpreter ComfyUI actually runs.
Fix 3: FFMPEG for video nodes
If you use WAS Node Suite or other video-processing custom nodes, FFMPEG must be on the system PATH and configured in was_suite_config.json.
- Download the full build from https://www.gyan.dev/ffmpeg/builds/ (
ffmpeg-git-full.7z) - Extract to
C:\ffmpegsoffmpeg.exesits atC:\ffmpeg\bin\ffmpeg.exe - Add
C:\ffmpeg\binto the system PATH (admin PowerShell):
``powershell [Environment]::SetEnvironmentVariable("Path", $env:Path + ";C:\ffmpeg\bin", "Machine") ``
- Edit
ComfyUI\custom_nodes\was-node-suite-comfyui\was_suite_config.json:
Use forward slashes even on Windows.
Verification checklist
After applying the fixes, launch via start_comfyui.bat and check the console:
| Check | Expected result |
|---|---|
| Custom nodes load | No IMPORT FAILED or ModuleNotFoundError lines |
| DWPose / ControlNet Aux | DWPose: Onnxruntime with acceleration providers detected |
| FFMPEG | No "ffmpeg not found" warnings |
| GPU acceleration | Using cuda:0 (or your GPU index) appears |
Test package location:
.\python_embeded\python.exe -m pip install emoji
.\python_embeded\python.exe -c "import emoji; print(emoji.__file__)"
The printed path should be inside your ComfyUI folder under python_embeded\Lib\site-packages.
Common errors and fixes
| Symptom | Cause (sourced) | Fix | Source |
|---|---|---|---|
ModuleNotFoundError: No module named 'xyz' | Package installed to user site-packages, not embedded environment | Install via .\python_embeded\python.exe -m pip install xyz | https://docs.python.org/3/using/cmdline.html |
IMPORT FAILED for custom node | Dependencies missing in embedded environment | Check node's requirements.txt and install each with embedded pip | https://civitai.com/articles/10251 |
| DWPose runs on CPU with warning | onnxruntime-gpu CUDA major version ≠ PyTorch CUDA major version | Install matching onnxruntime-gpu version (see table above) | https://onnxruntime.ai/docs/execution-providers/CUDA-ExecutionProvider.html |
| FFMPEG warning in console | FFMPEG not in PATH or wrong path in was_suite_config.json | Add to system PATH; set ffmpeg_bin_path with forward slashes | https://civitai.com/articles/10251 |
torch.version.cuda shows 12.1 but ORT needs 11.8 | Stale advice — modern ORT supports CUDA 12.x | Use ORT 1.17+ instead of downgrading PyTorch | https://onnxruntime.ai/docs/execution-providers/CUDA-ExecutionProvider.html |
FAQ
Why do my ComfyUI custom nodes fail to import even after pip install?
Because pip without a virtual environment installs to your user site-packages directory (AppData\Roaming\Python\...), but ComfyUI runs from its embedded Python which only sees its own python_embeded\Lib\site-packages. Set PYTHONNOUSERSITE=1 and use the embedded pip.
Do I need to downgrade PyTorch to CUDA 11.8 for DWPose?
No. That was necessary in early 2023. Since ONNX Runtime 1.17 (mid-2023), CUDA 12.x is supported. Since 1.27 (late 2024), the default onnxruntime-gpu is built for CUDA 13.0. Match the ORT version to your PyTorch CUDA version instead.
Where does pip.ini go on Windows?
%APPDATA%\pip\pip.ini. The pip documentation lists this as the per-user configuration file location for Windows 7 and later.
What does PYTHONNOUSERSITE=1 actually do?
It tells the Python interpreter not to add the user site-packages directory to sys.path. This is documented CPython behavior — not ComfyUI-specific.
Can I use a virtual environment instead of the embedded Python?
You can, but ComfyUI portable is designed to run on its embedded interpreter. Using the embedded Python with PYTHONNOUSERSITE=1 and correct PYTHONPATH is simpler and matches the distribution's intended setup.
Why forward slashes in was_suite_config.json?
The configuration parser expects forward slashes. Backslashes are escape characters in JSON strings and will break the path.
How do I know which CUDA version my PyTorch uses?
Run:
.\python_embeded\python.exe -c "import torch; print(torch.version.cuda)"
Output like 12.1 or 11.8 indicates the CUDA major.minor version.
Decision table: which onnxruntime-gpu to install
| If your PyTorch shows… | Install this onnxruntime-gpu | Pip command | Source |
|---|---|---|---|
12.1 – 12.8 (cu121/cu124/cu126/cu128) | 1.17.x – 1.26.x (CUDA 12.8) | pip install onnxruntime-gpu==1.18.0 | https://onnxruntime.ai/docs/execution-providers/CUDA-ExecutionProvider.html |
11.8 (cu118) | 1.18.x or 1.19.x (CUDA 11.8) | pip install onnxruntime-gpu==1.19.0 | https://onnxruntime.ai/docs/execution-providers/CUDA-ExecutionProvider.html |
13.0+ (cu130) | 1.27+ (CUDA 13.0) | pip install onnxruntime-gpu | https://onnxruntime.ai/docs/execution-providers/CUDA-ExecutionProvider.html |
Source for CUDA version matrix: https://onnxruntime.ai/docs/execution-providers/CUDA-ExecutionProvider.html Source for PyTorch wheel availability: https://download.pytorch.org/whl/torch_stable.html
- ComfyUI custom node development guide
- Managing multiple PyTorch versions with virtual environments
- FFMPEG setup for AI video workflows
Sources
| # | URL | Cited for |
|---|---|---|
| 1 | https://docs.python.org/3/using/cmdline.html | PYTHONNOUSERSITE behavior, -s flag |
| 2 | https://pip.pypa.io/en/stable/topics/configuration/ | pip.ini Windows location, [global] user = false |
| 3 | https://onnxruntime.ai/docs/execution-providers/CUDA-ExecutionProvider.html | ORT CUDA version matrix, PyTorch compatibility, preload_dlls |
| 4 | https://download.pytorch.org/whl/torch_stable.html | PyTorch wheel index existence |
| 5 | https://civitai.com/articles/10251 | pip.ini fix, start_comfyui.bat, FFMPEG config (single-source) |
| 6 | https://civitai.com/articles/3093 | DWPose warning text, stale CUDA 11.8 claim (corrected) |
| 7 | https://civitai.com/articles/4172 | ComfyUI output naming conventions (single-source) |