ERROR
pip
config_error
ai_generated
true
错误:无效需求:'<包名> ; extra == "test"' - 在额外说明符之后应为字符串结束
ERROR: Invalid requirement: '<package> ; extra == "test"' - Expected end of string after extra specifier
ID: pip/invalid-requirement-parse-error-from-env-markers
90%修复率
87%置信度
1证据数
2024-01-10首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| pip 21.0+ | active | — | — | — |
| Python 3.8-3.12 | active | — | — | — |
| setuptools 58+ | active | — | — | — |
根因分析
需求字符串包含环境标记(例如 extra、python_version),但语法不正确,例如缺少括号、多余空格或不支持的运算符。
English
The requirement string contains environment markers (e.g., extra, python_version) with incorrect syntax, such as missing parentheses, extra spaces, or unsupported operators.
官方文档
https://pip.pypa.io/en/stable/reference/requirements-file-format/#environment-markers解决方案
-
修正标记语法:使用 '包名 ; extra == "test"'(注意空格)或 '包名; extra == "test"'(分号前无空格)。对于多个条件:'包名; extra == "test" and python_version >= "3.8"'
-
pip install --dry-run -r requirements.txt 2>&1 | grep -E 'Invalid requirement'
-
将无效需求替换为更简单的版本:'包名[test]'(如果包中已定义 extra),或拆分为单独的需求行,使用 pip 的 --extra-index-url 进行条件安装。
无效尝试
常见但无效的做法:
-
Removing all environment markers from the requirement
70% 失败
This changes the package's dependency behavior, potentially breaking conditional dependencies.
-
Using double quotes instead of single quotes in the requirements file
95% 失败
The error is about marker syntax, not quote style; pip parses both quote types the same way.
-
Escaping the semicolon with a backslash
90% 失败
Backslash escaping is not supported in pip requirement strings; it will cause a different parse error.