pip install_error ai_generated true

错误:找不到 'setup.py' 文件用于可编辑安装 '<package>'。需要 setup.py 或 pyproject.toml。

ERROR: File 'setup.py' not found for editable install of '<package>'. A setup.py or pyproject.toml is required.

ID: pip/editable-install-no-setup-py

其他格式: JSON · Markdown 中文 · English
80%修复率
86%置信度
1证据数
2023-09-15首次发现

版本兼容性

版本状态引入弃用备注
pip 21.3+ active
Python 3.7-3.12 active

根因分析

以可编辑模式安装的包(pip install -e .)缺少 setup.py,并且 pyproject.toml 没有定义支持可编辑安装的有效构建后端(例如具有 build_editable 钩子的 setuptools 或 hatchling)。

English

The package being installed in editable mode (pip install -e .) lacks a setup.py, and the pyproject.toml does not define a valid build backend that supports editable installs (e.g., setuptools or hatchling with the build_editable hook).

generic

官方文档

https://pip.pypa.io/en/stable/topics/local-project-installs/#editable-installs

解决方案

  1. Add a pyproject.toml with a build backend that supports editable installs, e.g., using setuptools:
    [build-system]
    requires = ["setuptools>=64"]
    build-backend = "setuptools.build_meta"
    Then run pip install -e . again.
  2. If the project uses a modern backend like hatchling, ensure pyproject.toml includes:
    [build-system]
    requires = ["hatchling"]
    build-backend = "hatchling.build"
    [project]
    name = "<package>"
    version = "0.1.0"
    Then install with pip install -e .
  3. Use a symlink manually instead of editable install: ln -s /path/to/package /path/to/site-packages/<package> (Linux/macOS) or mklink /D (Windows). This bypasses pip's editable install mechanism.

无效尝试

常见但无效的做法:

  1. 70% 失败

    Without proper package discovery configuration, the editable install will fail or install nothing.

  2. 85% 失败

    This does not resolve the missing setup.py; it only disables build isolation.

  3. 60% 失败

    Older pip versions may work but are insecure and lack modern features; not a sustainable fix.