错误:无法为 somepkg 构建 wheel,这是安装基于 pyproject.toml 的项目所必需的 错误:子进程退出并报错 × 为 somepkg(pyproject.toml)构建 wheel 未成功运行。 │ 退出码:1 ╰─> [12 行输出] gcc: 错误:无法识别的命令行选项 '-mavx2'
ERROR: Could not build wheels for somepkg, which is required to install pyproject.toml-based projects error: subprocess-exited-with-error × Building wheel for somepkg (pyproject.toml) did not run successfully. │ exit code: 1 ╰─> [12 lines of output] gcc: error: unrecognized command-line option '-mavx2'
ID: python/pip-wheel-not-supported-platform
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 3.x | active | — | — | — |
根因分析
目标平台/Python 组合没有预构建 wheel,pip 回退到从源码构建,而本地工具链(gcc/clang)不支持所需标志或缺少头文件。
English
No prebuilt wheel exists for the target platform/Python combo, so pip falls back to building from source, and the local toolchain (gcc/clang) does not support the required flags or lacks headers.
解决方案
-
85% 成功率
Install build deps: apt-get install -y build-essential python3-dev (or xcode-select --install on macOS)
-
80% 成功率
Upgrade the compiler: on macOS 'brew install gcc' and set CC=gcc-13; on Linux use a newer distro or toolchain
-
75% 成功率
Use a prebuilt manylinux wheel from a different index: pip install --only-binary=:all: --extra-index-url https://download.pytorch.org/whl/cpu somepkg
无效尝试
常见但无效的做法:
-
90% 失败
Forces source builds for everything, making the failure more likely and slower.
-
85% 失败
Disables isolation but the compiler still lacks the required flags/headers.
-
95% 失败
The build failure is deterministic; retries produce the same compiler error.