python
module_error
ai_generated
true
ModuleNotFoundError: 没有名为 'distutils' 的模块 在处理上述异常期间,又发生另一个异常: ImportError: 无法从 setuptools 导入名称 'distutils'
ModuleNotFoundError: No module named 'distutils' During handling of the above exception, another exception occurred: ImportError: cannot import name 'distutils' from setuptools
ID: python/setuptools-distutils-removed
80%修复率
89%置信度
0证据数
2024-01-05首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 3.12 | active | — | — | — |
根因分析
Python 3.12 从标准库中移除了 distutils;由于 setuptools 过旧或环境遮蔽,setuptools 的垫片(setuptools._distutils)未生效。
English
Python 3.12 removed distutils from the standard library; setuptools' shim (`setuptools._distutils`) is not active because setuptools is too old or the environment shadows it.
解决方案
-
90% 成功率
Upgrade setuptools to a version that provides the distutils shim: `pip install --upgrade 'setuptools>=68'`.
-
70% 成功率
Set the env var `SETUPTOOLS_USE_DISTUTILS=stdlib` is wrong for 3.12; instead ensure `SETUPTOOLS_USE_DISTUTILS=local` and that setuptools is imported before distutils.
无效尝试
常见但无效的做法:
-
98% 失败
No such package exists on PyPI; distutils was bundled, not a standalone distribution.
-
90% 失败
Not possible without recreating the venv; the interpreter version is fixed.