python module_error ai_generated true

模块未找到错误:没有名为 'distutils' 的模块

ModuleNotFoundError: No module named 'distutils'

ID: python/setuptools-missing-distutils

其他格式: JSON · Markdown 中文 · English
80%修复率
88%置信度
0证据数
2024-04-02首次发现

版本兼容性

版本状态引入弃用备注
3.12 active — — —
3.13 active — — —

根因分析

Python 3.12 移除了标准库 distutils 模块。直接导入 distutils(或经由旧版 setuptools)的包或 setup.py 会失败,除非 setuptools 提供 distutils 兼容层。

English

Python 3.12 removed the stdlib distutils module. Packages or setup.py scripts that import distutils (directly or via old setuptools) fail unless setuptools provides the distutils shim.

generic

解决方案

  1. 85% 成功率
    pip install --upgrade 'setuptools>=68'
    # setuptools injects a distutils shim via SETUPTOOLS_USE_DISTUTILS=local
  2. 70% 成功率
    export SETUPTOOLS_USE_DISTUTILS=local
    pip install <pkg>
  3. 78% 成功率
    pyenv install 3.11.9 && pyenv local 3.11.9
    pip install <pkg>

无效尝试

常见但无效的做法:

  1. 95% 失败

    distutils was a stdlib module, never a PyPI package; the install fails.

  2. 95% 失败

    No such distribution exists.

  3. 80% 失败

    Very old setuptools is incompatible with Python 3.12 in other ways.