Stable Diffusion WebUI: No module named 'pkg_resources' (tested)

AUTOMATIC1111 Stable Diffusion WebUI fails at "Installing clip" with ModuleNotFoundError: No module named 'pkg_resources' when the venv has pip 25.3 or newer: pip builds the old CLIP commit in an isolated env with the newest setuptools. Tested fixes below.

1. Where the error comes from

On first launch, AUTOMATIC1111's modules/launch_utils.py runs python -m pip install <clip_package> --prefer-binary, where clip_package defaults to an old OpenAI CLIP commit:

clip_package = os.environ.get('CLIP_PACKAGE', "https://github.com/openai/CLIP/archive/d50d76daa670286dd6cacf3bcd80b5e4823fc8e1.zip")

That commit's setup.py line 3 imports pkg_resources. The venv's own setuptools still has it: a fresh Python 3.10 venv comes with an older setuptools, and the webui later pins setuptools==69.5.1 from requirements_versions.txt (that step runs after CLIP). But this only helps if pip builds CLIP with the venv's setuptools.

2. It depends on your pip version (tested)

We ran the same pip command in a Python 3.10 venv with setuptools 69.5.1 (adding --no-deps to skip downloading torch), changing only the pip version:

pipresult
22.2.1, 24.0, 25.2Successfully installed clip-1.0 (legacy setup.py build, uses the venv's setuptools 69.5.1)
25.3, 26.2.2fails: isolated build downloads the newest setuptools, which has no pkg_resources

With pip 26.2.2:

$ python -m pip install https://github.com/openai/CLIP/archive/d50d76daa670286dd6cacf3bcd80b5e4823fc8e1.zip --prefer-binary
Collecting https://github.com/openai/CLIP/archive/d50d76daa670286dd6cacf3bcd80b5e4823fc8e1.zip
  Downloading d50d76daa670286dd6cacf3bcd80b5e4823fc8e1.zip (4.3 MB)
  Installing build dependencies: started
  Installing build dependencies: finished with status 'done'
  Getting requirements to build wheel: started
  Getting requirements to build wheel: finished with status 'error'
  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 "/path/to/stable-diffusion-webui/venv/lib/python3.10/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 389, in <module>
          main()
        File "/path/to/stable-diffusion-webui/venv/lib/python3.10/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 373, in main
          json_out["return_val"] = hook(**hook_input["kwargs"])
        File "/path/to/stable-diffusion-webui/venv/lib/python3.10/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 143, in get_requires_for_build_wheel
          return hook(config_settings)
        File "/tmp/pip-xxx/overlay/lib/python3.10/site-packages/setuptools/build_meta.py", line 333, in get_requires_for_build_wheel
          return self._get_build_requires(config_settings, requirements=[])
        File "/tmp/pip-xxx/overlay/lib/python3.10/site-packages/setuptools/build_meta.py", line 301, in _get_build_requires
          self.run_setup()
        File "/tmp/pip-xxx/overlay/lib/python3.10/site-packages/setuptools/build_meta.py", line 520, in run_setup
          super().run_setup(setup_script=setup_script)
        File "/tmp/pip-xxx/overlay/lib/python3.10/site-packages/setuptools/build_meta.py", line 317, in run_setup
          exec(code, locals())  # noqa: S102 # exec is intentional here
        File "<string>", line 3, in <module>
      ModuleNotFoundError: No module named 'pkg_resources'
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
ERROR: Failed to build 'https://github.com/openai/CLIP/archive/d50d76daa670286dd6cacf3bcd80b5e4823fc8e1.zip' when getting requirements to build wheel

The webui prints this under "Couldn't install clip". So if you (or a script) upgraded pip in the webui venv to 25.3 or newer, this is why it broke.

3. Fixes (each tested with pip 26.2.2)

a) Tell pip's isolated build to use setuptools < 81. Create constraints.txt containing one line, setuptools<81, and set PIP_BUILD_CONSTRAINT. Linux/macOS, in webui-user.sh:

export PIP_BUILD_CONSTRAINT=/full/path/to/constraints.txt

Windows, in webui-user.bat: set PIP_BUILD_CONSTRAINT=C:\full\path\to\constraints.txt. Our run of the same install with the variable set ended with Successfully installed clip-1.0. (On pip 24.0 and older that variable is ignored, but those versions don't hit this error in the webui venv anyway; see the docker build guide for PIP_CONSTRAINT on older pip.)

b) Use the venv's setuptools instead of an isolated build:

venv/bin/python -m pip install --no-build-isolation https://github.com/openai/CLIP/archive/d50d76daa670286dd6cacf3bcd80b5e4823fc8e1.zip

Result: Successfully installed clip-1.0, built with the pinned setuptools 69.5.1. Once CLIP is installed the webui skips that step on later launches.

c) Downgrade pip in the webui venv to 25.2 or older (venv/bin/python -m pip install "pip<25.3"), which brings back the legacy build that worked in our table.

Forge: lllyasviel/stable-diffusion-webui-forge (main branch, last commit 2025-06-26) has the same clip_package default and the same setuptools==69.5.1 pin, so the same fixes apply. We checked its source; we did not run Forge itself.

The CLIP_PACKAGE variable also lets you point the webui at a newer CLIP commit. CLIP's main branch dropped pkg_resources from setup.py in Feb 2026; see the CLIP guide.

Related: No module named 'pkg_resources' (general fix) · CLIP · the deprecation warning.

Frequently asked questions

Why doesn't the webui's setuptools==69.5.1 pin help?

pip 25.3 and newer build CLIP in a separate isolated environment that downloads the latest setuptools, ignoring the venv's 69.5.1. pip 25.2 and older used the venv's setuptools for this package in our test.

Do I need to keep the fix forever?

Only until CLIP is installed. The webui installs CLIP only when it is missing, so later launches skip the failing step.

Written with AI assistance. Measured on 2026-10-24 on Linux, CPython 3.10.22, setuptools 69.5.1 (the webui's pin), pip 22.2.1, 24.0, 25.2, 25.3 and 26.2.2, installing the CLIP commit the webui uses. Output pasted unedited except shortened paths. PlainTables is our extension; Stable Diffusion WebUI and CLIP are free.