python
module_error
ai_generated
true
模块未找到错误:没有名为 'distutils' 的模块
ModuleNotFoundError: No module named 'distutils'
ID: python/setuptools-distutils-removed-python312
80%修复率
90%置信度
0证据数
2024-02-05首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 3.12 | active | — | — | — |
根因分析
Python 3.12 移除了标准库的 distutils 模块。导入 distutils 的旧版 setuptools 和遗留 setup.py 脚本会失败。setuptools >= 60 提供了内置的 distutils 兼容层,但前提是 SETUPTOOLS_USE_DISTUTILS 未设置为 stdlib。
English
Python 3.12 removed the stdlib distutils module. Older setuptools versions and legacy setup.py scripts that import distutils directly fail. setuptools >= 60 provides a vendored distutils shim but only if SETUPTOOLS_USE_DISTUTILS is not set to stdlib.
解决方案
-
92% 成功率
pip install --upgrade 'setuptools>=69' && export SETUPTOOLS_USE_DISTUTILS=local
-
80% 成功率
pip install standard-distutils # or use setuptools>=60 which vendors it
-
85% 成功率
pyenv install 3.11.9 && pyenv local 3.11.9
无效尝试
常见但无效的做法:
-
95% 失败
No such package exists on PyPI; distutils was a stdlib module, not a distributable package.
-
70% 失败
Old setuptools (<60) does not provide the shim, so the import still fails downstream.