错误:找不到 '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
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 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).
官方文档
https://pip.pypa.io/en/stable/topics/local-project-installs/#editable-installs解决方案
-
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.
-
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 .
-
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.
无效尝试
常见但无效的做法:
-
70% 失败
Without proper package discovery configuration, the editable install will fail or install nothing.
-
85% 失败
This does not resolve the missing setup.py; it only disables build isolation.
-
60% 失败
Older pip versions may work but are insecure and lack modern features; not a sustainable fix.