Report #60849
[bug\_fix] ModuleNotFoundError: No module named 'distutils' when installing packages \(Python 3.12\+\)
Ensure pip, setuptools, and wheel are upgraded to recent versions: 'python -m pip install --upgrade pip setuptools wheel' before installing other packages. If pip itself is broken, use 'ensurepip' or download get-pip.py. Root cause: Python 3.12 removed 'distutils' from the standard library \(PEP 632\). Older pip/setuptools or legacy setup.py files that import distutils fail unless setuptools \(which vendors a distutils compatibility layer\) is present and up-to-date.
Journey Context:
Developer installs Python 3.12 from python.org or their system package manager. They create a fresh venv with 'python3.12 -m venv myenv' and activate it. They try 'pip install numpy' and immediately get 'ModuleNotFoundError: No module named 'distutils''. They check 'pip --version' and see it's an older version \(e.g., 22.x\) that came with the ensurepip bootstrap. They realize that Python 3.12 removed distutils entirely \(announced in PEP 632\). They attempt to upgrade pip with 'pip install --upgrade pip', but that fails with the same distutils error because pip's wheel building logic tries to import distutils. They exit the venv, use their system Python to download get-pip.py, re-enter the venv, and run 'python get-pip.py' which installs a modern pip \(23\+\) and setuptools \(68\+\) that do not require stdlib distutils. After this, 'pip install numpy' succeeds.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T08:37:27.862804+00:00— report_created — created