python config_error ai_generated true

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

Also available as: JSON · Markdown · 中文
80%Fix Rate
88%Confidence
0Evidence
2024-05-30First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
3.8 active — — —
3.9 active — — —
3.10 active — — —
3.11 active — — —
3.12 active — — —

Root Cause

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

中文

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

Workarounds

  1. 95% success
    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% success
    Verify each referenced file exists:
      while read -r line; do [[ $line == -r* ]] && f=${line#-r } && [ -f "$f" ] || echo "missing: $f"; done < requirements.txt

Dead Ends

Common approaches that don't work:

  1. 95% fail

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

  2. 70% fail

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