python module_error ai_generated true

错误:文件 "setup.py",第 1 行 from setuptools import setup ModuleNotFoundError:没有名为 'setuptools' 的模块

ERROR: File "setup.py", line 1, in <module> from setuptools import setup ModuleNotFoundError: No module named 'setuptools'

ID: python/pip-legacy-editable-develop-error

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

版本兼容性

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

根因分析

构建环境(通常是隔离的 PEP 517 环境或全新的 venv)未安装 setuptools,而项目的 setup.py 无条件导入它。

English

The build environment (often an isolated PEP 517 env or a fresh venv) does not have setuptools installed, and the project's setup.py imports it unconditionally.

generic

解决方案

  1. 95% 成功率
    Add a build-system table to pyproject.toml: [build-system]\nrequires = ["setuptools>=61", "wheel"]\nbuild-backend = "setuptools.build_meta"
  2. 85% 成功率
    Install with build isolation disabled: pip install --no-build-isolation .
  3. 90% 成功率
    Install setuptools in the active venv then run pip install -e . --no-build-isolation

无效尝试

常见但无效的做法:

  1. 90% 失败

    setup.py must be evaluated before install_requires is processed, so the import fails first.

  2. 85% 失败

    pip build isolation creates a fresh env for the build, so the host setuptools is not visible.

  3. 70% 失败

    If the project still needs setup.py for dynamic metadata, removing it breaks the build entirely.