Report #78569
[bug\_fix] ModuleNotFoundError: No module named 'setuptools' during pip install in Python 3.12 venv
Add a \`pyproject.toml\` to the project root specifying the build system requirements: \`\[build-system\] requires = \["setuptools>=61.0", "wheel"\] build-backend = "setuptools.build\_meta"\`. This instructs pip to install setuptools in an isolated build environment even if the outer venv lacks it. Alternatively, manually install setuptools first: \`pip install setuptools\`.
Journey Context:
A developer creates a fresh virtual environment using Python 3.12: \`python3.12 -m venv .venv && source .venv/bin/activate\`. They clone a legacy repository containing a \`setup.py\` but no \`pyproject.toml\`. Running \`pip install .\` immediately fails with \`ModuleNotFoundError: No module named 'setuptools'\`. The developer is confused because this workflow worked for years with Python 3.10. Checking \`pip list\` reveals only \`pip\` and \`wheel\` are present; \`setuptools\` is missing. Researching, they discover that Python 3.12 no longer pre-installs setuptools in virtual environments \(PEP 632 deprecation, and changes in ensurepip/venv\). Because the legacy \`setup.py\` lacks a \`pyproject.toml\` declaring its build dependencies, pip assumes a legacy build but setuptools isn't available in the outer environment. Adding \`pyproject.toml\` with the \`\[build-system\]\` table triggers PEP 517 build isolation, causing pip to fetch setuptools automatically into a temporary build environment, resolving the import error.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T14:28:30.093856+00:00— report_created — created