uv: No module named 'pkg_resources' when building a package (tested)

uv add fails with ModuleNotFoundError: No module named 'pkg_resources' while building an old package. uv's hint to add pkg_resources as a build dependency fails. Tested fix: build-constraint-dependencies = ["setuptools<81"] under [tool.uv].

1. The error: uv add of a package whose setup.py imports pkg_resources

Our test package was cx_Oracle 8.3.0. It ships only an sdist for Python 3.11+, and its setup.py imports pkg_resources. In a fresh uv project:

$ uv add "cx_Oracle==8.3.0"
Resolved 2 packages in 96ms
   Building cx-oracle==8.3.0
error: Failed to add dependencies
  cause: Failed to build `cx-oracle==8.3.0`
  [... trimmed ...]
           File "<string>", line 6, in <module>
         ModuleNotFoundError: No module named 'pkg_resources'
hint: `cx-oracle` (v8.3.0) was included because `demo` (v0.1.0) depends on `cx-oracle`
hint: This error likely indicates that `cx-oracle@8.3.0` depends on `pkg_resources`, but doesn't declare it as a build dependency. If `cx-oracle` is a first-party package, consider adding `pkg_resources` to its `build-system.requires`. Otherwise, either add it to your `pyproject.toml` under:
[tool.uv.extra-build-dependencies]
cx-oracle = ["pkg_resources"]
or `uv pip install pkg_resources` into the environment and re-run with `--no-build-isolation`.

uv builds sdists in an isolated environment with the newest setuptools, and setuptools 82.0.0 removed pkg_resources. The setuptools in your .venv (if any) is not used by that build.

2. Don't follow the hint literally: there is no pkg_resources package

We added exactly what the hint suggests:

[tool.uv.extra-build-dependencies]
cx-oracle = ["pkg_resources"]
error: Failed to add dependencies
  cause: Failed to download and build `cx-oracle==8.3.0`
  cause: Failed to resolve requirements from `build-system.requires` and `extra-build-dependencies`
  cause: No solution found when resolving: `setuptools>=40.6.0`, `wheel`, `pkg-resources`
  cause: Because pkg-resources was not found in the package registry and you require pkg-resources, we can conclude that your requirements are unsatisfiable.

pkg_resources is a module inside setuptools, not a package on PyPI. What the build actually needs is an older setuptools.

3. Fix: constrain setuptools for builds in pyproject.toml

[tool.uv]
build-constraint-dependencies = ["setuptools<81"]
$ uv add "cx_Oracle==8.3.0"
      Built cx-oracle==8.3.0
Installed 1 package in 3ms
 + cx-oracle==8.3.0

This caps setuptools for every package uv builds in the project. To cap it for this one package only, this also worked:

[tool.uv.extra-build-dependencies]
cx-oracle = ["setuptools<81"]
      Built cx-oracle==8.3.0
Installed 1 package in 51ms

Without a project, uv pip install --build-constraint c.txt cx_Oracle (where c.txt contains setuptools<81) also installed it in our test. The long-term fix is to replace the old package. For cx_Oracle that means oracledb.

Same root cause elsewhere: No module named 'pkg_resources' (general fix) · openai CLIP · uv pip install vs uv add.

Frequently asked questions

Why doesn't uv pip install setuptools fix No module named pkg_resources?

uv builds packages in an isolated environment, so the setuptools in your .venv is not used. Constrain the build instead with build-constraint-dependencies or --build-constraint.

Is pkg_resources a package I can install?

No. It is a module inside setuptools, and setuptools 82 removed it. uv reports pkg-resources was not found in the package registry.

Written with AI assistance. Measured on 2026-10-24 on Linux with uv 0.13.5 and CPython 3.11.17, adding cx_Oracle 8.3.0 (sdist) to a fresh uv project. Output pasted unedited except shortened paths and marked trims. PlainTables is our extension; uv is free.