python
module_error
ai_generated
true
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%Fix Rate
89%Confidence
0Evidence
2024-01-05First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3.12 | active | — | — | — |
Root Cause
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.
generic中文
Python 3.12 从标准库中移除了 distutils;由于 setuptools 过旧或环境遮蔽,setuptools 的垫片(setuptools._distutils)未生效。
Workarounds
-
90% success
Upgrade setuptools to a version that provides the distutils shim: `pip install --upgrade 'setuptools>=68'`.
-
70% success
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.
Dead Ends
Common approaches that don't work:
-
98% fail
No such package exists on PyPI; distutils was bundled, not a standalone distribution.
-
90% fail
Not possible without recreating the venv; the interpreter version is fixed.