# 错误：无效需求：'package [extra1, extra2]'（requirements.txt 第 1 行）。提示：= 不是有效运算符。您是不是想用 ==？

- **ID:** `pip/invalid-requirement-extra-spacing`
- **领域:** pip
- **类别:** config_error
- **验证级别:** ai_generated
- **修复率:** 95%

## 根因

requirements.txt 包含无效语法，包名和 extras 方括号之间有空格，或使用了 '=' 而不是 '=='，导致 pip 解析失败。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| pip 23.3 | active | — | — |
| Python 3.9 | active | — | — |

## 解决方案

1. ```
   修复语法：移除空格并使用正确运算符。将 'package [extra1, extra2]' 改为 'package[extra1,extra2]'，并确保版本说明符使用 '==' 而不是 '='。
   ```
2. ```
   使用 pip 的解析功能进行验证：'pip install --dry-run -r requirements.txt' 以在完全安装前捕获语法错误。
   ```
3. ```
   手动安装后使用 'pip freeze' 重新生成 requirements.txt 以避免语法问题。
   ```

## 无效尝试

- **** — Adding a comment to requirements.txt does not fix the syntax error. (99% 失败率)
- **** — Running 'pip install --upgrade pip' does not change parsing rules; the syntax is still invalid. (95% 失败率)
- **** — Using 'pip install -r requirements.txt --ignore-requires-python' ignores Python version checks but not syntax errors. (98% 失败率)
