python module_error ai_generated true

ModuleNotFoundError:没有名为 'distutils' 的模块

ModuleNotFoundError: No module named 'distutils'

ID: python/setup-py-deprecated-distutils-removed

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

版本兼容性

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

根因分析

Python 3.12 移除了标准库 distutils 模块。旧的 setup.py 脚本或旧版 setuptools 直接导入 distutils 从而失败。

English

Python 3.12 removed the stdlib distutils module. Legacy setup.py scripts or old setuptools versions import distutils directly and fail.

generic

解决方案

  1. 90% 成功率
    pip install 'setuptools>=68'
    export SETUPTOOLS_USE_DISTUTILS=stdlib
    pip install .
  2. 85% 成功率
    pip install --upgrade setuptools
    python -c "import setuptools, setuptools._distutils; print('ok')"
    # if still failing, use build isolation:
    pip install --use-pep517 .

无效尝试

常见但无效的做法:

  1. 95% 失败

    There is no distutils package on PyPI; pip reports 'No matching distribution found for distutils'.

  2. 90% 失败

    The module doesn't exist to import; the shim itself raises ModuleNotFoundError.