python module_error ai_generated true

ModuleNotFoundError:没有名为 'setuptools._distutils.command.build_ext' 的模块

ModuleNotFoundError: No module named 'setuptools._distutils.command.build_ext'

ID: python/setup-py-install-requires-not-found

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

版本兼容性

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

根因分析

部分安装或降级后的 setuptools 缺少内置的 _distutils 子模块,通常发生在升级失败或 distutils 导入冲突之后。

English

A partially-installed or downgraded setuptools leaves the vendored _distutils submodule missing, often after a failed upgrade or a conflicting distutils import.

generic

解决方案

  1. 95% 成功率
    pip uninstall -y setuptools
    pip install --no-cache-dir 'setuptools>=68'
    python -c "from setuptools._distutils.command.build_ext import build_ext; print('ok')"
  2. 90% 成功率
    python -m venv .venv && source .venv/bin/activate
    pip install --upgrade pip setuptools wheel
    pip install .

无效尝试

常见但无效的做法:

  1. 95% 失败

    No such package on PyPI; pip returns 'No matching distribution found'.

  2. 70% 失败

    --no-deps can leave an inconsistent setuptools install if any dependency was previously removed.