python config_error ai_generated true

错误:无效的依赖项:'requests>=2..0'(来自 requirements.txt 第 1 行)

ERROR: Invalid requirement: 'requests>=2..0' (from line 1 of requirements.txt)

ID: python/pip-invalid-requirement-version-specifier

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

版本兼容性

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

根因分析

requirements.txt 中的版本说明符包含格式错误的版本号(例如双点、尾部操作符或说明符内部有空格),因此 pip 的 packaging 解析器在解析之前就拒绝了整行。

English

A version specifier in requirements.txt contains a malformed version number (e.g. double dots, trailing operators, or spaces inside the specifier), so pip's packaging parser rejects the whole line before resolving.

generic

解决方案

  1. 98% 成功率
    Edit requirements.txt:
      requests>=2.0
    Then re-run:
      pip install -r requirements.txt
  2. 95% 成功率
    python - <<'PY'
    from packaging.requirements import Requirement
    for i, line in enumerate(open('requirements.txt'), 1):
        line = line.strip()
        if not line or line.startswith('#'):
            continue
        try:
            Requirement(line)
        except Exception as e:
            print(f'line {i}: {line!r} -> {e}')
    PY

无效尝试

常见但无效的做法:

  1. 90% 失败

    pip delegates version parsing to packaging.version; the grammar is strict and unchanged across pip versions, so upgrading does nothing.

  2. 85% 失败

    Quotes become part of the requirement string and are still parsed as an invalid version, producing the same error.