# 错误：无效的约束：--hash=sha256:abc123...：期望约束行包含需求，但得到的是哈希选项

- **ID:** `pip/invalid-constraint-hash`
- **领域:** pip
- **类别:** config_error
- **错误码:** `ERROR`
- **验证级别:** ai_generated
- **修复率:** 95%

## 根因

约束文件（constraints.txt）中包含仅包含哈希选项的行（例如 --hash=sha256:...），但 pip 期望每个约束行指定一个包名和版本，哈希作为同一行的选项。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| pip 23.1 | active | — | — |
| pip 24.0 | active | — | — |
| pip 24.3 | active | — | — |

## 解决方案

1. ```
   将约束行重写为包含包名和版本：'package==1.2.3 --hash=sha256:abc123...'
   ```
2. ```
   从约束文件中移除孤立的哈希行，并使用以下命令重新生成哈希：pip hash <package>.whl
   ```

## 无效尝试

- **Add the hash to a requirements.txt instead of constraints.txt** — The same syntax rules apply to requirements files; moving the line does not fix the malformed constraint entry. (90% 失败率)
- **Use --require-hashes in constraints.txt** — The --require-hashes flag enables hash checking but does not change how constraint lines are parsed; the invalid line remains. (95% 失败率)
