ModuleNotFoundError: No module named ‘pkg_resources’

用户在 Windows 系统上按照官方指南安装 Stable Diffusion WebUI,运行 webui-user.bat 时,安装过程在安装 CLIP 依赖步骤失败。

ModuleNotFoundError: No module named 'pkg_resources'

ModuleNotFoundError: No module named ‘pkg_resources’

快速结论:该报错通常发生在 Stable Diffusion WebUI 安装过程最后阶段,当 pip 尝试从 GitHub 下载并构建 CLIP 包时,由于 setuptools 版本不兼容或缺少 pkg_resources 模块导致构建失败。优先排查 Python 环境中的 setuptools 版本和 pip 版本。

问题场景

用户在 Windows 系统上按照官方指南安装 Stable Diffusion WebUI,运行 webui-user.bat 时,安装过程在安装 CLIP 依赖步骤失败。

报错原文

RuntimeError: Couldn't install clip.
Command: "C:\1111\stable-diffusion-webui\venv\Scripts\python.exe" -m pip install https://github.com/openai/CLIP/archive/d50d76daa670286dd6cacf3bcd80b5e4823fc8e1.zip --prefer-binary
Error code: 1

stderr:   error: subprocess-exited-with-error

  Getting requirements to build wheel did not run successfully.
  exit code: 1

  [17 lines of output]
  Traceback (most recent call last):
    ...
    File "C:\Users\Donovan\AppData\Local\Temp\pip-build-env-fj81gqut\overlay\Lib\site-packages\setuptools\build_meta.py", line 333, in get_requires_for_build_wheel
      return self._get_build_requires(config_settings, requirements=[])
  ...
  ModuleNotFoundError: No module named 'pkg_resources'

原因分析

Issue 中用户报告 CLIP 包的构建过程失败,根本原因在于 pip 在构建 wheel 时依赖 setuptools,而环境中 setuptools 版本可能过旧或损坏,导致缺少 pkg_resources 模块。此外,部分用户提到 GitHub 认证问题可能影响包下载,但主要错误仍然是构建依赖问题。

环境排查

  • Python 版本:3.10.6(用户运行的环境)
  • 操作系统:Windows 10/11
  • WebUI 版本:v1.10.1-93-gfd68e0c3
  • 需要确认的包版本:setuptools、pip、wheel
  • GitHub 网络访问是否正常(CLIP 包托管在 GitHub)

解决步骤

  1. 更新虚拟环境中的 setuptools 和 pip(可优先尝试)

    # 激活 WebUI 的虚拟环境
    C:\1111\stable-diffusion-webui\venv\Scripts\activate
    # 升级 pip 和 setuptools
    python -m pip install --upgrade pip setuptools wheel
    # 重新运行 webui-user.bat
  2. 如果步骤1失败,手动安装 pkg_resources 兼容版本

    # 安装旧版本 setuptools(Issue 讨论中用户反馈有效)
    pip install setuptools==58.0.0
    # 重新运行 webui-user.bat
  3. 尝试使用 SSH 密钥解决 GitHub 认证问题

    如果错误信息包含 GitHub 认证失败(如 error 128),需要:

    • 在 GitHub 上生成 SSH 密钥并添加到账户
    • 在 WebUI 启动脚本中设置环境变量强制使用 SSH 协议
  4. 作为最后手段,使用替代仓库地址

    Issue 讨论中用户提供的替代仓库地址(非官方):

    set STABLE_DIFFUSION_REPO=https://github.com/joypaul162/Stability-AI-stablediffusion.git
    # 然后运行 webui-user.bat

    注意:使用非官方仓库存在安全风险,请谨慎评估后再尝试。

验证方法

重新运行 webui-user.bat,观察终端输出。如果安装过程顺利通过 CLIP 依赖步骤并进入 WebUI 主界面(浏览器打开 http://127.0.0.1:7860),说明问题已解决。

参考来源

AUTOMATIC1111/stable-diffusion-webui #17287

GamsGo AI

AI 工具推荐

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

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

了解 GamsGo AI

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

celebrityanime
celebrityanime
文章: 8640

发表回复

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