python encoding_error ai_generated true

错误:无法打开requirements文件:[Errno 22] 无效参数:'requirements.txt'

ERROR: Could not open requirements file: [Errno 22] Invalid argument: 'requirements.txt'

ID: python/pip-requirements-file-encoding

其他格式: JSON · Markdown 中文 · English
80%修复率
85%置信度
0证据数
2025-07-15首次发现

版本兼容性

版本状态引入弃用备注
3.9 active

根因分析

requirements文件具有无效编码(例如带BOM的UTF-16)或包含空字节。

English

The requirements file has an invalid encoding (e.g., UTF-16 with BOM) or contains null bytes.

generic

解决方案

  1. 90% 成功率 Convert file to UTF-8 encoding
    iconv -f UTF-16 -t UTF-8 requirements.txt > requirements_utf8.txt
    mv requirements_utf8.txt requirements.txt
  2. 85% 成功率 Recreate requirements file with proper encoding
    pip freeze > requirements.txt
    # Ensure editor saves as UTF-8

无效尝试

常见但无效的做法:

  1. Creating a new file with same name 80% 失败

    Does not fix encoding issue; may recreate with wrong encoding.

  2. Using --no-cache-dir 90% 失败

    Cache is irrelevant; file reading fails.