ERROR
pip
data_error
ai_generated
true
错误:requirements.txt 中的行具有无效的哈希格式:'sha256:abc123...' 哈希必须采用 'sha256:...' 格式(无空格,小写)。
ERROR: The line in requirements.txt has an invalid hash format: 'sha256:abc123...' The hash must be in the format 'sha256:...' (no spaces, lowercase).
ID: pip/requirements-hash-invalid-line
95%修复率
88%置信度
1证据数
2024-02-10首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| pip 23.3 | active | — | — | — |
| pip 24.0 | active | — | — | — |
| pip 24.1 | active | — | — | — |
根因分析
requirements.txt 文件中的哈希值格式错误,例如包含大写字母、空格或错误的算法前缀,导致 pip 在哈希验证期间拒绝整行。
English
A hash value in a requirements.txt file is malformed, e.g., contains uppercase letters, spaces, or incorrect algorithm prefix, causing pip to reject the entire line during hash verification.
官方文档
https://pip.pypa.io/en/stable/topics/secure-installs/#hash-checking-mode解决方案
-
使用 pip 内置工具重新生成哈希:pip hash /path/to/package.whl
-
手动修正 requirements.txt 中的哈希格式为小写并用冒号分隔:sha256:abcdef1234567890...
-
使用哈希生成脚本:python -c "import hashlib; print('sha256:' + hashlib.sha256(open('package.whl','rb').read()).hexdigest())"
无效尝试
常见但无效的做法:
-
50% 失败
Pip strictly parses the hash format; any deviation from 'algorithm:hexdigest' causes rejection.
-
80% 失败
Without the algorithm prefix, pip cannot determine which hash function to use for verification.