pip config_error ai_generated true

错误:无效需求:'package [extra1, extra2]'(requirements.txt 第 1 行)。提示:= 不是有效运算符。您是不是想用 ==?

ERROR: Invalid requirement: 'package [extra1, extra2]' (line 1 of requirements.txt). Hint: = is not a valid operator. Did you mean == ?

ID: pip/invalid-requirement-extra-spacing

其他格式: JSON · Markdown 中文 · English
95%修复率
88%置信度
1证据数
2023-11-12首次发现

版本兼容性

版本状态引入弃用备注
pip 23.3 active
Python 3.9 active

根因分析

requirements.txt 包含无效语法,包名和 extras 方括号之间有空格,或使用了 '=' 而不是 '==',导致 pip 解析失败。

English

The requirements.txt contains an invalid syntax with a space between the package name and brackets for extras, or uses '=' instead of '==', causing pip to fail parsing.

generic

官方文档

https://pip.pypa.io/en/stable/reference/requirements-file-format/#extras

解决方案

  1. 修复语法:移除空格并使用正确运算符。将 'package [extra1, extra2]' 改为 'package[extra1,extra2]',并确保版本说明符使用 '==' 而不是 '='。
  2. 使用 pip 的解析功能进行验证:'pip install --dry-run -r requirements.txt' 以在完全安装前捕获语法错误。
  3. 手动安装后使用 'pip freeze' 重新生成 requirements.txt 以避免语法问题。

无效尝试

常见但无效的做法:

  1. 99% 失败

    Adding a comment to requirements.txt does not fix the syntax error.

  2. 95% 失败

    Running 'pip install --upgrade pip' does not change parsing rules; the syntax is still invalid.

  3. 98% 失败

    Using 'pip install -r requirements.txt --ignore-requires-python' ignores Python version checks but not syntax errors.