Poetry: No module named 'pkg_resources' (PEP517 build failed, tested)
poetry add stops with "PEP517 build of a dependency failed" and ModuleNotFoundError: No module named 'pkg_resources'. Tested fix: cap setuptools for that package's build under [tool.poetry.build-constraints].
1. The error: poetry add of a package whose setup.py imports pkg_resources
Our test package was cx_Oracle 8.3.0. It has no wheel for Python 3.11, so Poetry builds it from the sdist, and its setup.py imports pkg_resources. In a fresh project with Poetry 2.5.1:
$ poetry add "cx_Oracle==8.3.0"
Package operations: 1 install, 0 updates, 0 removals
- Installing cx-oracle (8.3.0)
PEP517 build of a dependency failed
Backend subprocess exited when trying to invoke get_requires_for_build_wheel
| Traceback (most recent call last):
| [... trimmed ...]
| File "<string>", line 6, in <module>
| ModuleNotFoundError: No module named 'pkg_resources'
[... trimmed ...]
Poetry builds sdists in a temporary isolated venv (the /tmp/tmp.../.venv in the traceback) with the newest setuptools, and setuptools 82.0.0 removed pkg_resources. The project's own .venv is not used for that build, so installing setuptools there is not the fix.
2. Fix: build-constraints in pyproject.toml
Add this to pyproject.toml. The key is the package being built; the value caps setuptools inside its build venv:
[tool.poetry.build-constraints]
cx-oracle = { setuptools = "<81" }
$ poetry add "cx_Oracle==8.3.0"
Package operations: 1 install, 0 updates, 0 removals
- Installing cx-oracle (8.3.0)
Writing lock file
After that, .venv/bin/python -c "import cx_Oracle; print(cx_Oracle.version)" printed 8.3.0. Swap cx-oracle for whichever package fails (its name is in the "Installing ..." line just above the error). For cx_Oracle itself, the long-term fix is oracledb.
Same root cause elsewhere: No module named 'pkg_resources' (general fix) · uv · openai CLIP.
Frequently asked questions
Why doesn't installing setuptools in my Poetry venv fix it?
Poetry builds the package in a separate temporary venv with the newest setuptools. Constrain that build with [tool.poetry.build-constraints].
Which Poetry version supports build-constraints?
We tested Poetry 2.5.1. Check your version with poetry --version and upgrade if pyproject.toml rejects the section.
Written with AI assistance. Measured on 2026-10-24 on Linux with Poetry 2.5.1 and CPython 3.11.17, adding cx_Oracle 8.3.0 (sdist) to a fresh project. Output pasted unedited except shortened paths and marked trims. PlainTables is our extension; Poetry is free.