python config_error ai_generated true

错误:无效的需求:'requests >=2.0 <3.0'(来自 requirements.txt 第 4 行) 提示:= 不是有效的运算符。您是指 == 吗?

ERROR: Invalid requirement: 'requests >=2.0 <3.0' (from line 4 of requirements.txt) Hint: = is not a valid operator. Did you mean == ?

ID: python/pip-requirement-parse-error

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

版本兼容性

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

根因分析

需求行的版本说明符格式错误,通常是使用了单个 `=` 而非 `==`,或运算符之间有空格。

English

The requirement line has a malformed version specifier, often a single `=` instead of `==`, or a space between operators.

generic

解决方案

  1. 98% 成功率
    Change `requests >=2.0 <3.0` to `requests>=2.0,<3.0`
  2. 90% 成功率
    python -c "from packaging.requirements import Requirement; [Requirement(l.strip()) for l in open('requirements.txt') if l.strip() and not l.startswith('#')]"

无效尝试

常见但无效的做法:

  1. 90% 失败

    requirements.txt is parsed by pip, not the shell; quoting does not change the grammar.

  2. 85% 失败

    The parser is strict by design; upgrading does not accept invalid syntax.

  3. 95% 失败

    The error occurs during parsing, before resolution.