pip config_error ai_generated true

ERROR: Invalid requirement: 'package [extra1, extra2]' (line 1 of requirements.txt). Hint: = is not a valid operator. Did you mean == ?

ID: pip/invalid-requirement-extra-spacing

Also available as: JSON · Markdown · 中文
95%Fix Rate
88%Confidence
1Evidence
2023-11-12First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
pip 23.3 active
Python 3.9 active

Root Cause

The requirements.txt contains an invalid syntax with a space between the package name and brackets for extras, or uses '=' instead of '==', causing pip to fail parsing.

generic

中文

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

Official Documentation

https://pip.pypa.io/en/stable/reference/requirements-file-format/#extras

Workarounds

  1. 95% success Fix the syntax: remove spaces and use correct operator. Change 'package [extra1, extra2]' to 'package[extra1,extra2]' and ensure version specifier uses '==' not '='.
    Fix the syntax: remove spaces and use correct operator. Change 'package [extra1, extra2]' to 'package[extra1,extra2]' and ensure version specifier uses '==' not '='.
  2. 90% success Use pip's parsing to validate: 'pip install --dry-run -r requirements.txt' to catch syntax errors before full install.
    Use pip's parsing to validate: 'pip install --dry-run -r requirements.txt' to catch syntax errors before full install.
  3. 85% success Regenerate requirements.txt with 'pip freeze' after manual install to avoid syntax issues.
    Regenerate requirements.txt with 'pip freeze' after manual install to avoid syntax issues.

中文步骤

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

Dead Ends

Common approaches that don't work:

  1. 99% fail

    Adding a comment to requirements.txt does not fix the syntax error.

  2. 95% fail

    Running 'pip install --upgrade pip' does not change parsing rules; the syntax is still invalid.

  3. 98% fail

    Using 'pip install -r requirements.txt --ignore-requires-python' ignores Python version checks but not syntax errors.