ERROR
pip
config_error
ai_generated
true
错误:无效的约束:--hash=sha256:abc123...:期望约束行包含需求,但得到的是哈希选项
ERROR: Invalid constraint: --hash=sha256:abc123...: expected a constraint line with a requirement, got a hash option
ID: pip/invalid-constraint-hash
95%修复率
82%置信度
1证据数
2023-08-10首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| pip 23.1 | active | — | — | — |
| pip 24.0 | active | — | — | — |
| pip 24.3 | active | — | — | — |
根因分析
约束文件(constraints.txt)中包含仅包含哈希选项的行(例如 --hash=sha256:...),但 pip 期望每个约束行指定一个包名和版本,哈希作为同一行的选项。
English
A constraints file (constraints.txt) contains a line with only a hash option (e.g., --hash=sha256:...), but pip expects each constraint line to specify a package name and version, with the hash as an option on the same line.
官方文档
https://pip.pypa.io/en/stable/topics/constraints-files/解决方案
-
将约束行重写为包含包名和版本:'package==1.2.3 --hash=sha256:abc123...'
-
从约束文件中移除孤立的哈希行,并使用以下命令重新生成哈希:pip hash <package>.whl
无效尝试
常见但无效的做法:
-
Add the hash to a requirements.txt instead of constraints.txt
90% 失败
The same syntax rules apply to requirements files; moving the line does not fix the malformed constraint entry.
-
Use --require-hashes in constraints.txt
95% 失败
The --require-hashes flag enables hash checking but does not change how constraint lines are parsed; the invalid line remains.