ERROR 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/conflict-with-requirements-txt-extra

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

版本兼容性

版本状态引入弃用备注
pip 22.0 active
pip 23.1 active
pip 24.0 active

根因分析

requirements.txt 中的一行在 extras 规范后使用了单等号 (=) 进行版本固定,但 pip 要求使用双等号 (==) 表示精确版本约束。

English

A requirements.txt line uses a single equals sign (=) for version pinning after an extras specification, but pip requires double equals (==) for exact version constraints.

generic

官方文档

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

解决方案

  1. 编辑 requirements.txt 使用双等号:`package[extra1,extra2]==1.0`
  2. 如果不需要固定版本,移除版本说明符:`package[extra1,extra2]`
  3. 使用 `pip install -r requirements.txt --no-deps` 临时绕过无效行,然后修复文件。

无效尝试

常见但无效的做法:

  1. Remove the extras brackets entirely and reinstall without extras. 60% 失败

    The user may need the extras for functionality; removing them is a workaround but not a fix.

  2. Change the operator to >= instead of ==. 90% 失败

    The error is about the single equals sign, not the operator type; >= also requires double equals.

  3. Ignore the error and use `pip install package[extra1,extra2]==1.0` directly on CLI. 70% 失败

    The CLI command works, but the requirements.txt remains broken for future installs or CI.