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.
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.
python -m pip install --upgrade pip setuptools wheelDeclare it as a build requirement
For packaged projects, list setuptools in [build-system] requires so isolated builds provide it.
[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_resourcestoimportlib.metadata.