Skip to content
Latchkey

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".

build
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

  1. Add a [build-system] table to pyproject.toml.
  2. List setuptools and wheel in requires.
  3. Set build-backend = "setuptools.build_meta".
pyproject.toml
[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.

Terminal
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 requires over --no-build-isolation.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →