ArtificialGuyBR

Home / Blog / ComfyUI

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.

7 sources cited ComfyUI

TL;DR


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

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 versionCUDA versioncuDNNAvailability
1.17.x – 1.26.x12.x / 12.88.x / 9.xPyPI, NuGet
1.27.x+13.09.xPyPI, 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 CUDARecommended onnxruntime-gpuActionSource
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 resolvehttps://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.0https://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.

  1. Download the full build from https://www.gyan.dev/ffmpeg/builds/ (ffmpeg-git-full.7z)
  2. Extract to C:\ffmpeg so ffmpeg.exe sits at C:\ffmpeg\bin\ffmpeg.exe
  3. Add C:\ffmpeg\bin to the system PATH (admin PowerShell):

``powershell [Environment]::SetEnvironmentVariable("Path", $env:Path + ";C:\ffmpeg\bin", "Machine") ``

  1. 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:

CheckExpected result
Custom nodes loadNo IMPORT FAILED or ModuleNotFoundError lines
DWPose / ControlNet AuxDWPose: Onnxruntime with acceleration providers detected
FFMPEGNo "ffmpeg not found" warnings
GPU accelerationUsing 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

SymptomCause (sourced)FixSource
ModuleNotFoundError: No module named 'xyz'Package installed to user site-packages, not embedded environmentInstall via .\python_embeded\python.exe -m pip install xyzhttps://docs.python.org/3/using/cmdline.html
IMPORT FAILED for custom nodeDependencies missing in embedded environmentCheck node's requirements.txt and install each with embedded piphttps://civitai.com/articles/10251
DWPose runs on CPU with warningonnxruntime-gpu CUDA major version ≠ PyTorch CUDA major versionInstall matching onnxruntime-gpu version (see table above)https://onnxruntime.ai/docs/execution-providers/CUDA-ExecutionProvider.html
FFMPEG warning in consoleFFMPEG not in PATH or wrong path in was_suite_config.jsonAdd to system PATH; set ffmpeg_bin_path with forward slasheshttps://civitai.com/articles/10251
torch.version.cuda shows 12.1 but ORT needs 11.8Stale advice — modern ORT supports CUDA 12.xUse ORT 1.17+ instead of downgrading PyTorchhttps://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-gpuPip commandSource
12.112.8 (cu121/cu124/cu126/cu128)1.17.x – 1.26.x (CUDA 12.8)pip install onnxruntime-gpu==1.18.0https://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.0https://onnxruntime.ai/docs/execution-providers/CUDA-ExecutionProvider.html
13.0+ (cu130)1.27+ (CUDA 13.0)pip install onnxruntime-gpuhttps://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


Sources

#URLCited for
1https://docs.python.org/3/using/cmdline.htmlPYTHONNOUSERSITE behavior, -s flag
2https://pip.pypa.io/en/stable/topics/configuration/pip.ini Windows location, [global] user = false
3https://onnxruntime.ai/docs/execution-providers/CUDA-ExecutionProvider.htmlORT CUDA version matrix, PyTorch compatibility, preload_dlls
4https://download.pytorch.org/whl/torch_stable.htmlPyTorch wheel index existence
5https://civitai.com/articles/10251pip.ini fix, start_comfyui.bat, FFMPEG config (single-source)
6https://civitai.com/articles/3093DWPose warning text, stale CUDA 11.8 claim (corrected)
7https://civitai.com/articles/4172ComfyUI output naming conventions (single-source)

Media placeholders

System Python site-packages/ the package you just installed plain `pip install x` lands here package landed here ✗ not found ComfyUI_windows_portable/ python_embeded/ its own site-packages/ ComfyUI only searches this one ComfyUI looks here ← must go here Fix: python_embeded\\python.exe -m pip install x — install into the interpreter that runs ComfyUI.
Why `pip install` misses ComfyUI: two separate interpreters