python config_error ai_generated true

错误:无效的需求:'requirements.txt'(来自 requirements.txt 第 1 行) 提示:看起来像路径。文件 'requirements.txt' 不存在。

ERROR: Invalid requirement: 'requirements.txt' (from line 1 of requirements.txt) Hint: It looks like a path. File 'requirements.txt' does not exist.

ID: python/pip-invalid-requirement-no-such-file

其他格式: JSON · Markdown 中文 · English
80%修复率
88%置信度
0证据数
2024-05-30首次发现

版本兼容性

版本状态引入弃用备注
3.8 active — — —
3.9 active — — —
3.10 active — — —
3.11 active — — —
3.12 active — — —

根因分析

需求文件包含一行看起来像路径,但文件不存在,或者遗漏了 -r/-c,导致 pip 将文件名当作包名处理。

English

A requirements file includes a line that looks like a path but the file is missing, or -r/-c was omitted so pip treats a filename as a package name.

generic

解决方案

  1. 95% 成功率
    Use -r for nested requirements files:
      -r base.txt
      -r dev.txt
    And check paths are relative to the including file, not the CWD.
  2. 90% 成功率
    Verify each referenced file exists:
      while read -r line; do [[ $line == -r* ]] && f=${line#-r } && [ -f "$f" ] || echo "missing: $f"; done < requirements.txt

无效尝试

常见但无效的做法:

  1. 95% 失败

    Upgrade does not change how pip parses the line; the missing file still fails.

  2. 70% 失败

    If the path is relative and the CWD is different, renaming does not help; the resolution context is the issue.