python
module_error
ai_generated
true
ModuleNotFoundError: No module named 'distutils' File "setup.py", line 3, in <module> from distutils.core import setup
ID: python/setuptools-distutils-removed-python-312
80%Fix Rate
90%Confidence
0Evidence
2024-01-08First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3.12 | active | — | — | — |
| 3.13 | active | — | — | — |
Root Cause
Python 3.12 removed the stdlib `distutils` module (PEP 632). Legacy setup.py files and old setuptools versions (<60) import it directly, so building or installing the package fails on 3.12+.
generic中文
Python 3.12 移除了标准库 `distutils` 模块(PEP 632)。旧版 setup.py 和 setuptools(<60)会直接导入它,导致在 3.12+ 上构建或安装失败。
Workarounds
-
90% success
Upgrade setuptools to >=60, which vendors a distutils shim: pip install --upgrade "setuptools>=60" Then rebuild with `python -m build` or `pip install .`.
-
80% success
Install the standalone backport for tools that still need the real distutils: pip install setuptools pip install --upgrade pip # or, for legacy code: pip install setuptools==69.5.1 # last version with full shim For projects you control, migrate setup.py to pyproject.toml with the `[build-system]` table.
Dead Ends
Common approaches that don't work:
-
95% fail
There is no PyPI package named `distutils`; the module was stdlib-only. pip reports 'No matching distribution found'.
-
60% fail
setuptools' distutils shim is only installed when setuptools>=60 is present and even then some submodules (distutils.util, distutils.sysconfig) are not fully emulated.