python config_error ai_generated true

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

Also available as: JSON · Markdown · 中文
80%Fix Rate
90%Confidence
0Evidence
2024-06-11First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
3.8 active — — —
3.9 active — — —
3.10 active — — —
3.11 active — — —
3.12 active — — —

Root Cause

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

中文

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

Workarounds

  1. 98% success
    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% success
    Alternatively pass options on the CLI:
      pip install -r requirements.txt --extra-index-url https://example.com/simple

Dead Ends

Common approaches that don't work:

  1. 95% fail

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

  2. 90% fail

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