python config_error ai_generated true

错误:无效的需求:'--extra-index-url https://example.com/simple'(来自 requirements.txt 第 3 行) 提示:需求必须采用 'package[extras]==version' 的形式。

ERROR: Invalid requirement: '--extra-index-url https://example.com/simple' (from line 3 of requirements.txt) Hint: Requirements must be in the form 'package[extras]==version'.

ID: python/pip-requirements-parse-error-options

其他格式: JSON · Markdown 中文 · English
80%修复率
90%置信度
0证据数
2024-06-11首次发现

版本兼容性

版本状态引入弃用备注
3.8 active — — —
3.9 active — — —
3.10 active — — —
3.11 active — — —
3.12 active — — —

根因分析

像 --extra-index-url 这样的全局选项被放在 requirements.txt 中某个包行之后;pip 只接受位于文件顶部的全局选项,在任何需求之前。

English

A global option like --extra-index-url is placed after a package line in requirements.txt; pip only accepts global options at the top of the file, before any requirement.

generic

解决方案

  1. 98% 成功率
    Move all global options to the top of requirements.txt:
      --extra-index-url https://example.com/simple
      --trusted-host example.com
      foo==1.2.3
      bar>=2.0
  2. 95% 成功率
    Alternatively pass options on the CLI:
      pip install -r requirements.txt --extra-index-url https://example.com/simple

无效尝试

常见但无效的做法:

  1. 95% 失败

    Quoting turns it into an invalid package name; pip still rejects it.

  2. 90% 失败

    Global options are only valid before the first requirement; moving to the end does not help.