python install_error ai_generated true

错误:无效的需求:'requests ==2.31.0'

ERROR: Invalid requirement: 'requests ==2.31.0'

ID: python/pip-invalid-requirement-double-equals-space

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

版本兼容性

版本状态引入弃用备注
3.x active — — —

根因分析

pip 的需求解析器将包名与版本说明符之间的空格视为独立 token,因此 'requests ==2.31.0' 被解析为两个无效需求。

English

Pip's requirement parser treats a space between the package name and the version specifier as a separate token, so 'requests ==2.31.0' is parsed as two invalid requirements.

generic

解决方案

  1. 99% 成功率
    Remove the space: pip install requests==2.31.0
  2. 99% 成功率
    Use the PEP 508 form with no space: pip install 'requests==2.31.0'
  3. 98% 成功率
    Put it in requirements.txt with no space: echo 'requests==2.31.0' > requirements.txt && pip install -r requirements.txt

无效尝试

常见但无效的做法:

  1. 85% 失败

    Quoting preserves the space; pip still sees the invalid token split and raises the same Invalid requirement error.

  2. 90% 失败

    The shell passes a literal backslash-space to pip, which is not a valid requirement character and still fails parsing.

  3. 95% 失败

    The syntax error is independent of the shell/terminal; the malformed requirement string is the cause.