python module_error ai_generated true

ModuleNotFoundError: No module named 'distutils' File ".../setuptools/_distutils/__init__.py", line 1, in <module>

ID: python/setuptools-no-module-named-distutils

Also available as: JSON · Markdown · 中文
80%Fix Rate
90%Confidence
0Evidence
2024-01-08First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
3.12 active — — —
3.13 active — — —

Root Cause

Python 3.12 removed the stdlib `distutils`. Older setuptools versions that rely on it break; also affects packages importing distutils directly.

generic

中文

Python 3.12 移除了标准库 `distutils`。依赖它的旧版 setuptools 会出错;也影响直接导入 distutils 的包。

Workarounds

  1. 90% success
    python -m pip install --upgrade 'setuptools>=68' wheel
    python -m pip install <package>
  2. 70% success
    export SETUPTOOLS_USE_DISTUTILS=local
    python -m pip install --upgrade setuptools

Dead Ends

Common approaches that don't work:

  1. 95% fail

    There is no installable `distutils` package on PyPI; it was a stdlib module.

  2. 60% fail

    If setuptools is already installed but old, pip may not upgrade it in the same invocation that fails.