Report #66726
[bug\_fix] ModuleNotFoundError: No module named 'distutils' \(Python 3.12\+\)
Upgrade \`setuptools\` to version 65.0.0 or newer \(\`pip install --upgrade setuptools wheel\`\) before installing the legacy package. Modern setuptools provides a \`distutils\` compatibility shim. For packages with unpatched \`setup.py\`, ensure you are not using an isolated build \(\`--no-build-isolation\` might be needed if build-backend is missing, though usually upgrading setuptools is sufficient\).
Journey Context:
A developer upgrades their project to Python 3.12. They create a fresh virtual environment and attempt to install an older version of a dependency \(e.g., \`pip install somepackage==0.5.0\`\). The installation fails with \`ModuleNotFoundError: No module named 'distutils'\`. The traceback shows the error occurs in the package's \`setup.py\` on the line \`from distutils.core import setup\`. The developer knows that \`setuptools\` is present but realizes that Python 3.12 removed \`distutils\` from the standard library \(PEP 632\). They research and find that while \`distutils\` is gone, modern versions of \`setuptools\` \(v65\+\) provide a shim that intercepts \`distutils\` imports and redirects them to \`setuptools\` implementations. The developer runs \`pip install --upgrade setuptools wheel\` to get the latest shim-capable version, then re-runs the install of the legacy package, which now succeeds because \`import distutils\` resolves to the setuptools compatibility layer.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T18:28:50.147487+00:00— report_created — created