错误:无效的需求:'package==1.0 ; extra == "test"' - 在额外说明符之后预期字符串结束
ERROR: Invalid requirement: 'package==1.0 ; extra == "test"' - Expected end of string after extra specifier
ID: pip/requirements-file-syntax-error-extra
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| pip 19.0+ | active | — | — | — |
| Python 3.6-3.12 | active | — | — | — |
根因分析
requirements.txt 中的 extras 语法格式错误:pip 期望 extras 条件是一个简单的标记表达式,无需引用 extra 名称,或者 extra 名称必须匹配有效的 PEP 508 标记。
English
The extras syntax in requirements.txt is malformed: pip expects the extras condition to be a simple marker expression without quoting the extra name, or the extra name must match a valid PEP 508 marker.
官方文档
https://pip.pypa.io/en/stable/reference/requirements-file-format/解决方案
-
Use the correct PEP 508 marker syntax: package==1.0; extra == "test" (no space before semicolon, extra value in double quotes). Example: package==1.0; extra == "test"
-
Use a separate requirements file for extras: create requirements-test.txt with just package==1.0 and install with pip install -r requirements-test.txt
无效尝试
常见但无效的做法:
-
90% 失败
The quotes are interpreted as part of the package name or marker, causing a different parse error.
-
75% 失败
Pip expects the marker value to be a string literal in quotes, e.g., extra == "test", not an unquoted identifier.
-
85% 失败
Pip does not support comma-separated extras in requirements.txt; it's invalid syntax.