错误:找不到用于构建项目的后端。该项目使用一个尚未安装的构建后端。构建后端为 '<backend_name>'。
ERROR: Could not find a backend for building the project. The project uses a build backend that is not installed. The build backend is '<backend_name>'.
ID: pip/pep-517-backend-not-found-during-build
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| pip 21.3 | active | — | — | — |
| pip 23.1 | active | — | — | — |
| pip 24.0 | active | — | — | — |
根因分析
pyproject.toml 指定了一个构建后端(例如 `setuptools.build_meta`、`flit_core.buildapi`、`maturin`),但该后端未在当前环境中安装,导致 pip 在尝试构建包时失败。
English
The pyproject.toml specifies a build backend (e.g., `setuptools.build_meta`, `flit_core.buildapi`, `maturin`) that is not installed in the current environment, causing pip to fail when trying to build the package.
官方文档
https://packaging.python.org/en/latest/tutorials/packaging-projects/#configuring-metadata解决方案
-
显式安装缺失的构建后端:`pip install <backend_name>`(例如 `pip install setuptools` 或 `pip install flit_core`),然后重试原始安装。
-
使用 `pip install <package> --no-build-isolation --no-deps` 并通过环境变量手动提供后端:`PIP_REQUIRE_VIRTUALENV=false pip install <package> --no-build-isolation`
无效尝试
常见但无效的做法:
-
90% 失败
This flag disables build isolation but does not install the missing backend; pip will still fail if the backend is not available in the environment.
-
95% 失败
The `--no-deps` flag only affects runtime dependencies, not build dependencies; the build backend is a build dependency and is still required.