python
encoding_error
ai_generated
true
错误:异常: 回溯(最近一次调用最后): 文件 "/usr/lib/python3/dist-packages/pip/_internal/req/req_file.py",第 84 行,在 parse_requirements 中 line = line.decode('utf-8') UnicodeDecodeError:'utf-8' 编解码器无法解码位置 0 中的字节 0xff:无效起始字节
ERROR: Exception: Traceback (most recent call last): File "/usr/lib/python3/dist-packages/pip/_internal/req/req_file.py", line 84, in parse_requirements line = line.decode('utf-8') UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte
ID: python/pip-unicode-decode-error-requirements
80%修复率
87%置信度
0证据数
2024-03-25首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 3.8 | active | — | — | — |
| 3.9 | active | — | — | — |
| 3.10 | active | — | — | — |
| 3.11 | active | — | — | — |
| 3.12 | active | — | — | — |
根因分析
需求文件不是 UTF-8 编码,通常由于 Windows 工具保存为 UTF-16 或 Latin-1。
English
The requirements file is not encoded in UTF-8, often due to Windows tools saving as UTF-16 or Latin-1.
解决方案
-
90% 成功率
Convert the file to UTF-8: `iconv -f UTF-16 -t UTF-8 requirements.txt > requirements_utf8.txt`.
-
95% 成功率
In a text editor, save as UTF-8 without BOM.
无效尝试
常见但无效的做法:
-
70% 失败
Loses content; may not fix encoding if the tool saves in wrong format again.
-
90% 失败
Still reads the file and fails on encoding.