# 错误：无效需求：'<包名> ; extra == "test"' - 在额外说明符之后应为字符串结束

- **ID:** `pip/invalid-requirement-parse-error-from-env-markers`
- **领域:** pip
- **类别:** config_error
- **错误码:** `ERROR`
- **验证级别:** ai_generated
- **修复率:** 90%

## 根因

需求字符串包含环境标记（例如 extra、python_version），但语法不正确，例如缺少括号、多余空格或不支持的运算符。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| pip 21.0+ | active | — | — |
| Python 3.8-3.12 | active | — | — |
| setuptools 58+ | active | — | — |

## 解决方案

1. ```
   修正标记语法：使用 '包名 ; extra == "test"'（注意空格）或 '包名; extra == "test"'（分号前无空格）。对于多个条件：'包名; extra == "test" and python_version >= "3.8"'
   ```
2. ```
   pip install --dry-run -r requirements.txt 2>&1 | grep -E 'Invalid requirement'
   ```
3. ```
   将无效需求替换为更简单的版本：'包名[test]'（如果包中已定义 extra），或拆分为单独的需求行，使用 pip 的 --extra-index-url 进行条件安装。
   ```

## 无效尝试

- **Removing all environment markers from the requirement** — This changes the package's dependency behavior, potentially breaking conditional dependencies. (70% 失败率)
- **Using double quotes instead of single quotes in the requirements file** — The error is about marker syntax, not quote style; pip parses both quote types the same way. (95% 失败率)
- **Escaping the semicolon with a backslash** — Backslash escaping is not supported in pip requirement strings; it will cause a different parse error. (90% 失败率)
