ERROR
pip
config_error
ai_generated
true
ERROR: Invalid requirement: '<package> ; extra == "test"' - Expected end of string after extra specifier
ID: pip/invalid-requirement-parse-error-from-env-markers
90%Fix Rate
87%Confidence
1Evidence
2024-01-10First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| pip 21.0+ | active | — | — | — |
| Python 3.8-3.12 | active | — | — | — |
| setuptools 58+ | active | — | — | — |
Root Cause
The requirement string contains environment markers (e.g., extra, python_version) with incorrect syntax, such as missing parentheses, extra spaces, or unsupported operators.
generic中文
需求字符串包含环境标记(例如 extra、python_version),但语法不正确,例如缺少括号、多余空格或不支持的运算符。
Official Documentation
https://pip.pypa.io/en/stable/reference/requirements-file-format/#environment-markersWorkarounds
-
95% success Correct the marker syntax: use 'package ; extra == "test"' (note the spacing) or 'package; extra == "test"' (no space before semicolon). For multiple conditions: 'package; extra == "test" and python_version >= "3.8"'
Correct the marker syntax: use 'package ; extra == "test"' (note the spacing) or 'package; extra == "test"' (no space before semicolon). For multiple conditions: 'package; extra == "test" and python_version >= "3.8"'
-
85% success pip install --dry-run -r requirements.txt 2>&1 | grep -E 'Invalid requirement'
pip install --dry-run -r requirements.txt 2>&1 | grep -E 'Invalid requirement'
-
80% success Replace the invalid requirement with a simpler version: 'package[test]' if the extra is defined in the package itself, or split into separate requirement lines with conditional installation using pip's --extra-index-url.
Replace the invalid requirement with a simpler version: 'package[test]' if the extra is defined in the package itself, or split into separate requirement lines with conditional installation using pip's --extra-index-url.
中文步骤
修正标记语法:使用 '包名 ; 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 进行条件安装。
Dead Ends
Common approaches that don't work:
-
Removing all environment markers from the requirement
70% fail
This changes the package's dependency behavior, potentially breaking conditional dependencies.
-
Using double quotes instead of single quotes in the requirements file
95% fail
The error is about marker syntax, not quote style; pip parses both quote types the same way.
-
Escaping the semicolon with a backslash
90% fail
Backslash escaping is not supported in pip requirement strings; it will cause a different parse error.