ModuleNotFoundError: No module named ‘comfy’

该报错通常出现在使用 ComfyUI-Manager 安装自定义节点包(git clone 阶段)时,成功下载列表后克隆仓库失败,错误指向 git_helper.py 导入 comfy 模块失败。优先确认 ComfyUI-Manager 版本,Issue 结论为该问题在 4.1 中修复,4.0.x

快速结论:该报错通常出现在使用 ComfyUI-Manager 安装自定义节点包(git clone 阶段)时,成功下载列表后克隆仓库失败,错误指向 git_helper.py 导入 comfy 模块失败。优先确认 ComfyUI-Manager 版本,Issue 结论为该问题在 4.1 中修复,4.0.x 受影响的用户应升级到 4.1 或更高版本。

适用环境:Issue 中确认的环境为 Windows、Python 3.12.9、PyTorch 2.8.0+cu129、NVIDIA GeForce RTX 4090(VRAM 24564 MB)、ComfyUI 0.10.0,ComfyUI-Manager 为 4.0.5(pip 显示已满足 comfyui_manager 4.0.5)。

最快修复方案:在 ComfyUI 使用的 Python 环境中将 ComfyUI-Manager 升级到 4.1 或更高版本,Issue 维护者给出的命令为 pip install -U comfyui-manager;升级后重新尝试安装节点包。

注意事项:Issue 的修复说明是针对 4.0.x 的 git_helper.py 导入问题;若升级到 4.1 或更高版本后仍然出现完全相同的报错,Issue 建议带上日志新开 Issue,而不是继续沿用本问题的结论。执行升级前请确认命令作用于 ComfyUI 实际使用的虚拟环境,避免升级到其他 Python 环境。

问题场景

用户在 Windows 上的 ComfyUI 环境中通过 ComfyUI-Manager 安装节点包扩展(例如日志中的 ComfyMath,仓库地址 https://github.com/evanspearman/ComfyMath)。在更新到 ComfyUI-Manager 0.11.1(日志中 pip 显示包版本为 4.0.5)后,安装任意节点包均失败:列表获取成功,但 git clone 阶段调用 git_helper.py 时抛出 ModuleNotFoundError。Issue 正文说明该问题对尝试的所有包都会出现。

报错原文

FETCH DATA from: C:\...\ComfyUI\.venv\Lib\site-packages\comfyui_manager\custom-node-list.json [DONE]
Download: git clone 'https://github.com/evanspearman/ComfyMath'
[!] Traceback (most recent call last):
[!]   File "C:\...\ComfyUI\.venv\Lib\site-packages\comfyui_manager\common\git_helper.py", line 12, in <module>
[!]     from comfyui_manager.common.timestamp_utils import get_backup_branch_name
[!]   File "C:\...\ComfyUI\.venv\Lib\site-packages\comfyui_manager\__init__.py", line 6, in <module>
[!]     from comfy.cli_args import args
[!] ModuleNotFoundError: No module named 'comfy'
[ComfyUI-Manager] Installation failed:
Failed to clone repo: https://github.com/evanspearman/ComfyMath

After restarting ComfyUI, please refresh the browser.

原因分析

根据 Issue 中的修复说明,git_helper.py 在 4.0.x 中为执行 git clone 作为独立进程运行,但它会导入 comfyui_manager 包,而该包又依赖 ComfyUI 的 comfy 模块;在这个独立进程中 comfy 模块不可导入,因此触发 ModuleNotFoundError: No module named ‘comfy’。该问题已在 4.1 中修复,修复方式是让该 helper 不再导入 comfyui_manager 包。除此之外,若 comfy 模块本身无法被当前 Python 环境导入(例如运行环境不一致),也可能出现类似导入错误,但这并非本 Issue 已确认的根因。

环境排查

  • 确认 ComfyUI-Manager 的实际版本:Issue 中 pip 显示为 4.0.5,属于受影响的 4.0.x 系列。
  • 确认执行升级命令时使用的是 ComfyUI 对应的 Python 虚拟环境(Issue 日志路径为 C:\...\ComfyUI\.venv),避免在系统 Python 或其他环境中升级。
  • 确认 Python 版本为 3.12.9(Issue 环境),升级后仍失败时可将该版本一并写入新 Issue 日志。
  • 确认 PyTorch 版本为 2.8.0+cu129、显卡为 RTX 4090、ComfyUI 版本为 0.10.0,便于对照是否仍处于相同环境。
  • 确认失败发生在 git clone 阶段,并且报错仍指向 git_helper.py 与 comfy 模块导入。

解决步骤

  1. 在 ComfyUI 使用的 Python 环境(Issue 中为 ComfyUI 目录下的 .venv)中执行 pip install -U comfyui-manager,将 ComfyUI-Manager 升级到 4.1 或更高版本。
  2. 升级完成后,可重新查看 pip 输出或包版本信息,确认版本号不低于 4.1,而不是仍停留在 4.0.x。
  3. 重启 ComfyUI,使新的 ComfyUI-Manager 代码生效。
  4. 重新通过 ComfyUI-Manager 安装之前失败的节点包(如 ComfyMath),确认 git clone 阶段不再出现 comfy 模块导入错误。
  5. 如果升级到 4.1 或更高版本后仍以相同方式失败,按 Issue 维护者建议,携带完整日志新开 Issue 反馈。

验证方法

升级并重启后再次安装同一节点包,日志中应能正常完成 git clone,不再出现 ModuleNotFoundError: No module named 'comfy',也不再出现 [ComfyUI-Manager] Installation failed: Failed to clone repo。随后刷新浏览器,确认节点包已出现在节点列表中且可正常使用。

参考来源

ltdrdata/ComfyUI-Manager #2556(Issue 讨论中给出的修复版本为 4.1,修复 PR 编号 #2703)

GamsGo AI

AI 工具推荐

想把多个 AI 模型放在一个入口?

GamsGo AI 集成 ChatGPT、DeepSeek、Gemini、Claude、Midjourney、Veo 等常用模型,适合写作、绘图、视频和日常 AI 工作流。

了解 GamsGo AI

推广链接:通过此链接购买,我可能获得佣金,不影响你的价格。

这个方案解决了吗?

celebrityanime
celebrityanime
文章: 35055

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注