python config_error ai_generated true

错误:无效的依赖项:'Requires-Python: >=3.8'

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

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

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

版本兼容性

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

根因分析

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

English

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

解决方案

  1. 98% 成功率
    # requirements.txt should look like:
    requests>=2.31
    numpy==1.26.4
    # Remove any 'Name:', 'Version:', 'Requires-Python:' lines.
  2. 95% 成功率
    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

无效尝试

常见但无效的做法:

  1. 60% 失败

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

  2. 90% 失败

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