build "No module named setuptools" under build isolation in CI
PEP 517 builds run in an isolated environment that contains only what [build-system] requires lists. If setuptools is not declared, the backend import fails with No module named 'setuptools' even though setuptools is installed in the outer venv.
What this error means
During pip install . or python -m build, the backend import fails with "ModuleNotFoundError: No module named 'setuptools'", typically right after "Preparing metadata (pyproject.toml)" or "Getting requirements to build wheel".
Getting requirements to build wheel ... error
ModuleNotFoundError: No module named 'setuptools'Common causes
setuptools is not in build-system.requires
The isolated build environment installs only the packages in [build-system] requires. An empty or missing requires (or one that omits setuptools) leaves the backend with no setuptools to import.
A pyproject with no [build-system] but a setup.py
Newer pip assumes a default backend; if you rely on setuptools implicitly but never declare it, the isolated env will not have it.
How to fix it
Declare setuptools (and wheel) in build-system.requires
- Add a
[build-system]table to pyproject.toml. - List
setuptoolsandwheelinrequires. - Set
build-backend = "setuptools.build_meta".
[build-system]
requires = ["setuptools>=61", "wheel"]
build-backend = "setuptools.build_meta"Disable isolation only as a last resort
If you must use the outer environment's setuptools, pass --no-build-isolation, but then you must pre-install every build dependency yourself.
pip install --no-build-isolation .How to prevent it
- Always declare a
[build-system]table, even for setuptools projects. - Treat the isolated build env as empty: list every backend dependency.
- Prefer fixing
requiresover--no-build-isolation.