Report #104704
[bug\_fix] \`ModuleNotFoundError: No module named 'distutils'\` when installing packages via pip in Python 3.12\+ because distutils was removed from the standard library
Install setuptools explicitly before using pip: \`pip install setuptools\`. For new environments, use \`pip install --upgrade pip setuptools wheel\`. If distutils is needed by a specific package, pin Python to 3.11 or set \`SETUPTOOLS\_USE\_DISTUTILS=stdlib\`.
Journey Context:
A developer was setting up a fresh Python 3.12 virtual environment on a clean Ubuntu 24.04 server. They ran \`pip install -r requirements.txt\`, which included the \`gevent\` library. The install failed with \`ModuleNotFoundError: No module named 'distutils'\`. The developer checked \`pip list\`—no distutils package. They tried installing \`python3-distutils\` via apt, but apt reported it was not available for Python 3.12. The root cause was that Python 3.12 removed the deprecated \`distutils\` module from the standard library \(it was already deprecated in Python 3.10 and removed in 3.12\). Many packages \(like \`gevent\`, \`scipy\`, \`numpy\`\) still used \`distutils\` in their setup scripts. The established fix was to ensure \`setuptools\` \(which provides \`distutils\` as a backward-compatibility shim\) is installed. The developer added \`setuptools\` as a first line in \`requirements.txt\` and ran \`pip install setuptools\` before the main install, which resolved the issue. Moving forward, they set \`SETUPTOOLS\_USE\_DISTUTILS=stdlib\` in the environment as a fallback.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-09-27T20:11:58.205939+00:00— report_created — created