Report #7261
[bug\_fix] ModuleNotFoundError: No module named 'distutils' in Python 3.12 venv
Ensure the \`setuptools\` package is installed in the venv by upgrading pip and setuptools immediately after creation: \`pip install --upgrade pip setuptools\`, or ensure the \`ensurepip\` module was available when creating the venv. The root cause is that Python 3.12 removed \`distutils\` \(PEP 632\), and pip relies on \`setuptools\` \(which provides a compatibility shim for \`distutils\`\) to install packages from source; if setuptools is missing, imports fail.
Journey Context:
You install Python 3.12, create a venv with \`python3.12 -m venv venv\`, activate it, and run \`pip install requests\`. You get \`ModuleNotFoundError: No module named 'distutils'\`. You check \`pip --version\` and it works, but any install fails. You search and find PEP 632 explaining distutils removal in 3.12. You check \`pip list\` and see \`setuptools\` is not installed. You try \`pip install setuptools\` but it fails with the same distutils error because pip needs setuptools to install setuptools from source. You realize the venv was created without \`ensurepip\` or the \`setuptools\` bundled wheel. You deactivate, install the OS package \`python3.12-ensurepip\` or \`python3.12-venv\` \(on Debian/Ubuntu\), recreate the venv, and this time \`setuptools\` is present. Alternatively, you download \`get-pip.py\` and run it with the venv Python to bootstrap pip/setuptools correctly. After this, \`pip install\` works because \`setuptools\` provides the missing \`distutils\` compatibility layer.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T02:14:22.723199+00:00— report_created — created