Skip to content
Latchkey

Python "ModuleNotFoundError: No module named setuptools" in CI

Something imported setuptools or pkg_resources and the interpreter has neither. Newer Python venvs no longer ship setuptools by default, so legacy build scripts that assume it fail.

What this error means

A build, setup.py, or import pkg_resources step fails with "ModuleNotFoundError: No module named 'setuptools'" on Python 3.12+ or a bare venv.

python
Traceback (most recent call last):
  File "setup.py", line 1, in <module>
    from setuptools import setup
ModuleNotFoundError: No module named 'setuptools'

Common causes

setuptools is no longer bundled by default

Python 3.12+ venvs omit setuptools, so any code importing it (or pkg_resources) fails until you install it.

A disabled build isolation env

With --no-build-isolation, pip does not provision setuptools, so a setuptools-based backend has nothing to import.

How to fix it

Install setuptools explicitly

Add setuptools (and wheel) to the environment that runs the build.

Terminal
python -m pip install --upgrade pip setuptools wheel

Declare it as a build requirement

For packaged projects, list setuptools in [build-system] requires so isolated builds provide it.

pyproject.toml
[build-system]
requires = ["setuptools>=64", "wheel"]
build-backend = "setuptools.build_meta"

How to prevent it

  • Do not assume setuptools/pkg_resources exist in fresh venvs.
  • Install setuptools as an explicit dependency where you import it.
  • Migrate off pkg_resources to importlib.metadata.

Related guides

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