pip config_error ai_generated true

错误:无效的需求:'package==1.0 ; extra == "test"' - 在额外说明符之后预期字符串结束

ERROR: Invalid requirement: 'package==1.0 ; extra == "test"' - Expected end of string after extra specifier

ID: pip/requirements-file-syntax-error-extra

其他格式: JSON · Markdown 中文 · English
92%修复率
88%置信度
1证据数
2023-06-08首次发现

版本兼容性

版本状态引入弃用备注
pip 19.0+ active
Python 3.6-3.12 active

根因分析

requirements.txt 中的 extras 语法格式错误:pip 期望 extras 条件是一个简单的标记表达式,无需引用 extra 名称,或者 extra 名称必须匹配有效的 PEP 508 标记。

English

The extras syntax in requirements.txt is malformed: pip expects the extras condition to be a simple marker expression without quoting the extra name, or the extra name must match a valid PEP 508 marker.

generic

官方文档

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

解决方案

  1. Use the correct PEP 508 marker syntax: package==1.0; extra == "test" (no space before semicolon, extra value in double quotes). Example:
    package==1.0; extra == "test"
  2. Use a separate requirements file for extras: create requirements-test.txt with just package==1.0 and install with pip install -r requirements-test.txt

无效尝试

常见但无效的做法:

  1. 90% 失败

    The quotes are interpreted as part of the package name or marker, causing a different parse error.

  2. 75% 失败

    Pip expects the marker value to be a string literal in quotes, e.g., extra == "test", not an unquoted identifier.

  3. 85% 失败

    Pip does not support comma-separated extras in requirements.txt; it's invalid syntax.