No module named 'cv2' in ComfyUI: OpenCV Fix
Fix No module named 'cv2' in ComfyUI, missing opencv-python-headless, opencv-contrib-python, and OpenCV package conflicts.
Start with Wonderful Launcher if this issue touches your real ComfyUI environment. Use the docs to understand the fix, and use the app to inspect the machine you already have.
Download Wonderful LauncherSymptoms
When ComfyUI starts, the terminal log shows:
ModuleNotFoundError: No module named 'cv2'or:
Cannot import ... module for custom nodes: No module named 'cv2'Sometimes the terminal does not mention cv2 first. It may appear through pip check lines like:
albumentations requires opencv-python-headless, which is not installed
mediapipe requires opencv-contrib-python, which is not installed
mmcv requires opencv-python, which is not installedThose package names are different, but they point to the same shared OpenCV family.
Cause
OpenCV provides the cv2 module used by many custom nodes for resizing, cropping, pose preprocessing, segmentation masks, video frames, and color conversion. ControlNet helper nodes, VideoHelperSuite, Impact Pack, face tools, and many workflow utility nodes can depend on it.
This error is typically caused by one of the following:
- No OpenCV package is installed in the Python environment that starts ComfyUI.
- Multiple OpenCV package flavors are installed and overwrite the shared
cv2namespace. - OpenCV imports but fails because of a NumPy or native DLL mismatch.
OpenCV package naming
The official PyPI OpenCV packages all provide the same cv2 module:
| Package | Contents | Use case |
|---|---|---|
opencv-python | Core modules + GUI support | When GUI windows such as cv2.imshow are needed |
opencv-python-headless | Core modules, no GUI | Servers/background processing; usually best for ComfyUI |
opencv-contrib-python | Core + extra modules + GUI | Extra algorithms plus GUI |
opencv-contrib-python-headless | Core + extra modules, no GUI | Extra algorithms without GUI |
For ComfyUI, opencv-python-headless is usually the safer default because ComfyUI does not need OpenCV GUI windows, and headless avoids extra Qt/GUI dependencies.
Important: keep only one OpenCV package flavor installed at a time.
Packages that often surface the OpenCV error
In ComfyUI support cases, OpenCV problems often show up through the dependent package rather than through cv2 directly:
| Package Named in the Error | Common OpenCV Requirement |
|---|---|
albumentations, albucore, rembg | opencv-python-headless |
mediapipe, inference-gpu | opencv-contrib-python |
pixeloe, facexlib, groundingdino-py, supervision, ultralytics, mmcv | opencv-python |
Do not install every OpenCV flavor just because different packages name different variants. Pick one flavor that fits the environment, verify import cv2, and then test the workflow that actually needs it.
Severity
Medium - OpenCV is foundational for many custom nodes, but install it only in the Python environment that actually runs ComfyUI.
Before installing: use the correct Python
| Install type | Command pattern |
|---|---|
| Official GitHub Windows portable package | From the portable package root: .\python_embeded\python.exe -s -m pip ... |
| Manual Git + venv install | Activate the venv, then run python -m pip ... |
| ComfyUI Desktop or managed launcher | Use the app's environment/terminal tools. Do not assume a portable python_embeded folder exists. |
Solution
Step 1: Diagnose the current state
Check which OpenCV packages are installed:
python -m pip list | findstr opencvFor the official Windows portable package:
.\python_embeded\python.exe -s -m pip list | findstr opencvIf multiple OpenCV packages appear, clean them up before reinstalling one flavor.
Step 2: Clean up and install
Case 1: No OpenCV package is installed
python -m pip install opencv-python-headlessCase 2: Already installed but throwing errors, or multiple OpenCV packages are present
python -m pip uninstall -y opencv-python opencv-python-headless opencv-contrib-python opencv-contrib-python-headless
python -m pip install opencv-python-headlessCase 3: NumPy conflict during installation or import
Do not downgrade NumPy globally as a first move. Current ComfyUI environments can legitimately use NumPy 2.x, while older plugins may still expect NumPy 1.x.
If the log names a specific NumPy/OpenCV compatibility error, choose a single OpenCV version that supports the NumPy stack you are keeping, or isolate the old plugin in a separate environment.
Case 4: pip check says another package requires OpenCV
If the only symptom is a pip check line, first check whether the plugin imports and whether your workflow uses it. A missing OpenCV declaration is not always a fatal ComfyUI startup error.
If the workflow is blocked, install one OpenCV flavor and test:
python -m pip install opencv-python-headless
python -c "import cv2; print(cv2.__version__)"If a package specifically needs contrib modules, use opencv-contrib-python-headless instead of stacking it on top of opencv-python-headless.
Step 3: Verify the installation
python -c "import cv2; print(cv2.__version__)"If a version number is printed, restart ComfyUI and check whether the plugin imports.
Still not resolved?
If cv2 still fails after cleanup, collect:
- output of
python -m pip list | findstr opencv - output of
python -m pip list | findstr numpy - the full
IMPORT FAILEDtraceback - your install type: portable, Desktop, manual venv, or managed launcher
Then use expert help if you need the fastest recovery path.
Source References
Start with Wonderful Launcher if this issue touches your real ComfyUI environment. Use the docs to understand the fix, and use the app to inspect the machine you already have.
Download Wonderful LauncherStart with Wonderful Launcher if this issue touches your real ComfyUI environment. Use the docs to understand the fix, and use the app to inspect the machine you already have.
Download Wonderful LauncherDid this fix your issue?
Your answer helps prioritize verified ComfyUI repairs.
InsightFace Missing
Fix No module named 'insightface' in ComfyUI for ReActor, IPAdapter FaceID, InstantID, PuLID, and other face-swap or face-analysis nodes on Windows.
Custom Nodes
Install ComfyUI custom nodes with Manager or manual Git clone, avoid dependency drift, and fix red nodes, import failures, or Manager node-list errors safely.