错误:无法为 foo 构建 wheel,这是安装基于 pyproject.toml 的项目所必需的 × 准备元数据(pyproject.toml)未能成功运行。 ╰─> BackendUnavailable: 无法导入 'setuptools.build_meta'
ERROR: Could not build wheels for foo, which is required to install pyproject.toml-based projects × Preparing metadata (pyproject.toml) did not run successfully. ╰─> BackendUnavailable: Cannot import 'setuptools.build_meta'
ID: python/pip-build-backend-not-found
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 3.9 | active | — | — | — |
| 3.10 | active | — | — | — |
| 3.11 | active | — | — | — |
| 3.12 | active | — | — | — |
根因分析
pyproject.toml [build-system].build-backend 中声明的构建后端无法在隔离的构建环境中导入,通常是因为后端包未列入 [build-system].requires。
English
The build backend declared in pyproject.toml [build-system].build-backend cannot be imported inside the isolated build environment, usually because the backend package is not listed in [build-system].requires.
解决方案
-
95% 成功率
Add the backend to requires in pyproject.toml: [build-system] requires = ["setuptools>=61", "wheel"] build-backend = "setuptools.build_meta" For hatchling: requires = ["hatchling"], build-backend = "hatchling.build"
-
80% 成功率
If you only consume the package, install the backend manually then build without isolation: pip install setuptools wheel pip install --no-build-isolation foo
无效尝试
常见但无效的做法:
-
70% 失败
Without isolation, the backend must already be installed in your env; if it is not, the same error occurs.
-
90% 失败
pip version does not affect whether the build backend is importable.