python module_error ai_generated true

在 pip install -e . 期间出现 ModuleNotFoundError:没有名为 'setuptools' 的模块(pyproject.toml 构建后端)

ModuleNotFoundError: No module named 'setuptools' during pip install -e . (pyproject.toml build backend)

ID: python/pip-build-isolation-missing-setuptools

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

版本兼容性

版本状态引入弃用备注
3.x active — — —

根因分析

pyproject.toml 声明 setuptools.build_meta 作为后端,但构建隔离环境或项目的 build-system.requires 未包含 setuptools。

English

A pyproject.toml declares setuptools.build_meta as the backend, but the build isolation environment or the project's build-system.requires does not include setuptools.

generic

解决方案

  1. 95% 成功率
    Declare the build requirement in pyproject.toml:
    [build-system]
    requires = ["setuptools>=61", "wheel"]
    build-backend = "setuptools.build_meta"
  2. 90% 成功率
    Install build deps explicitly then build:
    pip install setuptools wheel build
    python -m build

无效尝试

常见但无效的做法:

  1. 65% 失败

    Uses the current env, which may also lack setuptools or have an incompatible version; masks the real config bug.

  2. 75% 失败

    Installs in the outer env but build isolation still creates a fresh env without it.