python config_error ai_generated true

ERROR: Invalid requirement: 'Requires-Python: >=3.8'

ID: python/pip-requires-python-invalid-metadata

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

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
3.8 active
3.9 active
3.10 active
3.11 active
3.12 active

Root Cause

A requirements.txt file contains package metadata lines (like Requires-Python or Name:) pasted from a PKG-INFO; pip's requirement parser rejects them.

generic

中文

requirements.txt 包含从 PKG-INFO 粘贴的包元数据行(如 Requires-Python 或 Name:),pip 的依赖解析器会拒绝它们。

Workarounds

  1. 98% success
    # requirements.txt should look like:
    requests>=2.31
    numpy==1.26.4
    # Remove any 'Name:', 'Version:', 'Requires-Python:' lines.
  2. 95% success
    pip freeze > requirements.txt
    # verify each line parses
    python - <<'PY'
    from packaging.requirements import Requirement
    for i, l in enumerate(open('requirements.txt'),1):
        l=l.strip()
        if l and not l.startswith('#'):
            Requirement(l)
    print('ok')
    PY

Dead Ends

Common approaches that don't work:

  1. 60% fail

    If other metadata lines remain, parsing still fails; also hides the actual intent of the file.

  2. 90% fail

    --no-deps skips dependency resolution, not requirement parsing; the invalid line still errors.