# 错误：legacy-install-failure
× 尝试安装包时遇到错误。
╰─> numpy

注意：这是上述包的问题，不是 pip 的问题。

- **ID:** `pip/legacy-install-failure-numpy`
- **领域:** pip
- **类别:** build_error
- **错误码:** `error`
- **验证级别:** ai_generated
- **修复率:** 88%

## 根因

包（例如 numpy）需要旧版构建系统（setup.py），但由于缺少构建依赖项或编译器问题而失败，通常是因为该包未提供针对该平台的预编译 wheel。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| pip 21.0 | active | — | — |
| pip 23.0 | active | — | — |
| pip 24.0 | active | — | — |

## 解决方案

1. ```
   如果可用，安装预编译 wheel：`pip install numpy --only-binary :all:` 或使用 `pip install numpy==1.24.3`（该版本为大多数平台提供 wheel）。
   ```
2. ```
   安装系统构建依赖：在 Ubuntu 上运行 `sudo apt-get install python3-dev build-essential`；在 macOS 上运行 `xcode-select --install`。
   ```
3. ```
   使用 conda 作为替代方案：`conda install numpy` 提供预编译的二进制文件。
   ```

## 无效尝试

- **Reinstall pip and retry, assuming pip itself is broken.** — The error is from the package's build system, not pip's installation. (90% 失败率)
- **Use `pip install --no-build-isolation numpy` without fixing the underlying build tools.** — This may expose more errors but doesn't fix missing compilers or libraries. (70% 失败率)
- **Install numpy from a different index without verifying the version.** — The same build failure will occur if no pre-built wheel exists. (80% 失败率)
