No module named 'groundingdino' or 'segment_anything' in ComfyUI
Fix ComfyUI ModuleNotFoundError for groundingdino or segment_anything in SAM, GroundingDINO, masking, and segmentation workflows.
Community Knowledge
This page is based on common ComfyUI troubleshooting patterns and has not been fully tested across all environments. Back up your environment before changing packages.
If ComfyUI logs ModuleNotFoundError: No module named 'groundingdino' or ModuleNotFoundError: No module named 'segment_anything', a segmentation custom node failed before it could register its ComfyUI nodes.
These errors often appear in SAM, GroundingDINO, masking, background removal, and object segmentation workflows. They are not ComfyUI core packages. They usually belong to a custom node such as comfyui_segment_anything or another segmentation pack that imports SAM or GroundingDINO during startup.
In the full Wonderful Launcher telemetry export ending June 29, 2026, groundingdino appeared across 20 affected installs, including 6 affected installs in the last 30 days. segment_anything appeared across 11 affected installs, including 4 affected installs in the last 30 days. Treat them as one segmentation repair chain unless the startup log names a different plugin.
Fast answer
Fix the first missing import in the Python environment that starts ComfyUI. For the GitHub Windows portable package:
.\python_embeded\python.exe -s -m pip install groundingdino-py
.\python_embeded\python.exe -s -m pip install git+https://github.com/facebookresearch/segment-anything.git
.\python_embeded\python.exe -s ComfyUI\main.py --windows-standalone-buildOnly run the package that matches the error you actually see. You may still need GroundingDINO and SAM model files after the Python imports are fixed.
What the error looks like
GroundingDINO import failure:
IMPORT FAILED: comfyui_segment_anything
Traceback (most recent call last):
File "...\custom_nodes\comfyui_segment_anything\__init__.py", line 1, in <module>
import groundingdino
ModuleNotFoundError: No module named 'groundingdino'SAM import failure:
IMPORT FAILED: ComfyUI-SAM
Traceback (most recent call last):
File "...\custom_nodes\ComfyUI-SAM\__init__.py", line 5, in <module>
from segment_anything import sam_model_registry, SamPredictor
ModuleNotFoundError: No module named 'segment_anything'Common custom nodes that can trigger this class of error include comfyui_segment_anything, ComfyUI-SAM, ComfyUI-Impact-Pack features, background removal nodes, and other segmentation-related packs.
SAM package, SAM model, or GroundingDINO?
Segmentation workflows can fail at several layers:
| Error or symptom | Likely layer | First action |
|---|---|---|
No module named 'groundingdino' | GroundingDINO Python package is missing | Install groundingdino-py only in ComfyUI's Python, then restart |
No module named 'segment_anything' | SAM Python package is missing | Install Segment Anything from the official source into ComfyUI's Python |
| GroundingDINO node loads but no GroundingDINO model is available | Model or config file is missing | Put model/config files in the folder expected by the custom node |
| SAM node loads but no SAM checkpoint is available | Model file is missing | Put the .pth checkpoint in the folder expected by that node |
No module named 'pycocotools' | Detection/segmentation helper dependency is missing | Install only if the same plugin imports it |
| Red SAM/DINO nodes after install | Plugin still failed to import | Read the first IMPORT FAILED traceback |
Do not install every segmentation package at once. Fix the first missing import, restart, and then follow the next visible error.
Why it happens
- The custom node was cloned but its dependencies were not installed
- SAM and GroundingDINO are plugin-specific dependencies, not ComfyUI core dependencies
- A previous environment rebuild or update removed it
- The package was installed in a different Python environment than the one ComfyUI uses
- The Python package is fixed, but required model or config files are still missing
Quick diagnosis
| Check | Command (portable) | Expected |
|---|---|---|
| Is GroundingDINO installed? | .\python_embeded\python.exe -s -m pip show groundingdino-py | Shows version |
| Can GroundingDINO import? | .\python_embeded\python.exe -s -c "import groundingdino; print('ok')" | Prints ok |
| Can Segment Anything import? | .\python_embeded\python.exe -s -c "import segment_anything; print('ok')" | Prints ok |
| Which node needs it? | Read IMPORT FAILED in startup log | Names the custom node |
| Are GroundingDINO files present? | Check ComfyUI\models\grounding-dino\ or the plugin README | Contains expected config and model files |
| Is the SAM model downloaded? | Check ComfyUI\models\sams\ or the plugin README | Contains .pth file |
Safe manual fix
Step 1: Install only the missing import
If the error says groundingdino:
For Windows portable:
.\python_embeded\python.exe -s -m pip install groundingdino-pyFor a manual venv:
python -m pip install groundingdino-pyIf the error says segment_anything, use the official Segment Anything source:
.\python_embeded\python.exe -s -m pip install git+https://github.com/facebookresearch/segment-anything.gitFor a manual venv:
python -m pip install git+https://github.com/facebookresearch/segment-anything.gitThere is also a segment-anything package on PyPI, but Meta's official repository documents the GitHub install path. Prefer the plugin README when it gives a specific command.
Step 2: Download the model files required by the plugin
The Python packages provide code. Segmentation workflows also need model files.
For comfyui_segment_anything, the README expects GroundingDINO files under:
ComfyUI\models\grounding-dino\and SAM checkpoints under:
ComfyUI\models\sams\For SAM, common checkpoint choices include:
- SAM ViT-H (default, largest):
sam_vit_h_4b8939.pth(~2.4 GB) - SAM ViT-L (large):
sam_vit_l_0b3195.pth(~1.2 GB) - SAM ViT-B (base, smallest):
sam_vit_b_01ec64.pth(~375 MB)
The exact folder depends on your custom node's configuration. Check the node's README for the expected model location.
Step 3: Check for additional dependencies
Some SAM-based nodes also require:
.\python_embeded\python.exe -s -m pip install pycocotoolsOnly install extra packages if the startup log shows additional import errors after fixing the first missing package.
Step 4: Restart and verify
.\python_embeded\python.exe -s ComfyUI\main.py --windows-standalone-buildThe SAM or GroundingDINO-related nodes should now appear in the node list. If the plugin imports cleanly but execution fails at GroundingDinoModelLoader or SAMModelLoader, switch from Python-package repair to model-file placement.
When not to run pip install blindly
- Segment Anything depends on
torchandtorchvision. If your environment already has CUDA-enabled PyTorch, avoid package commands that replace Torch or TorchVision unexpectedly - GroundingDINO may compile or install native pieces depending on the package path, CUDA, Python, and platform. Stop if the error changes into a compiler, CUDA, or wheel failure
- Some custom nodes bundle their own SAM code instead of using the pip package. Check whether the node README says to install from pip or from the node's own requirements
- Do not install
segment-anything-pyor other similarly named packages — they may be forks with different APIs - Do not keep reinstalling Python packages when the next error is a missing
.pth, config file, or Hugging Face model directory
How Wonderful Launcher can help
Wonderful Launcher can help separate the repair stages: plugin import, missing Python package, model file placement, and queue-time runtime errors. That matters for SAM/GroundingDINO workflows because fixing the Python import often reveals a second model-file issue.
Download Wonderful Launcher — it's free and can recover your environment without reinstalling.
Related errors
- ComfyUI Plugin Import Failed
- Fix No module named errors in ComfyUI
- ComfyUI ONNX Missing
- ComfyUI Dependency Conflicts
- ComfyUI Startup Failed
- Plugin Missing Module Warning: When It Is Safe to Ignore
Source References
Start free with Wonderful Launcher if this affects your real ComfyUI environment. If the repair is blocking work, Agent Access is the paid guided path; credits are for image generation and metered tools.
Download Wonderful LauncherSee Agent AccessDid this fix your issue?
Your answer helps prioritize verified ComfyUI repairs.
OpenCV / cv2 Missing
Fix ModuleNotFoundError: No module named 'cv2' in ComfyUI, missing opencv-python-headless, opencv-contrib-python, and OpenCV package conflicts.
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.