python
module_error
ai_generated
true
ModuleNotFoundError:没有名为 'distutils' 的模块 File ".../setuptools/_distutils/__init__.py", 第 1 行, 在 <module> 中
ModuleNotFoundError: No module named 'distutils' File ".../setuptools/_distutils/__init__.py", line 1, in <module>
ID: python/setuptools-no-module-named-distutils
80%修复率
90%置信度
0证据数
2024-01-08首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 3.12 | active | — | — | — |
| 3.13 | active | — | — | — |
根因分析
Python 3.12 移除了标准库 `distutils`。依赖它的旧版 setuptools 会出错;也影响直接导入 distutils 的包。
English
Python 3.12 removed the stdlib `distutils`. Older setuptools versions that rely on it break; also affects packages importing distutils directly.
解决方案
-
90% 成功率
python -m pip install --upgrade 'setuptools>=68' wheel python -m pip install <package>
-
70% 成功率
export SETUPTOOLS_USE_DISTUTILS=local python -m pip install --upgrade setuptools
无效尝试
常见但无效的做法:
-
95% 失败
There is no installable `distutils` package on PyPI; it was a stdlib module.
-
60% 失败
If setuptools is already installed but old, pip may not upgrade it in the same invocation that fails.