Skip to content
Latchkey

pip "Invalid requirement" - Fix requirements.txt Parse Errors

pip could not parse a line in your requirements file or command. The syntax is wrong - a bad version operator, a stray character, or a URL/editable line in the wrong form.

What this error means

pip stops immediately with Invalid requirement and points at the offending text. Nothing installs because pip never gets past parsing the requirement.

pip output
ERROR: Invalid requirement: 'requests = 2.31.0' (from line 3 of requirements.txt)
Hint: = is not a valid operator. Did you mean == ?

Common causes

Wrong version operator or spacing

pip wants package==2.31.0, not package = 2.31.0. A single =, stray spaces around the operator, or smart quotes copied from a doc all break parsing.

A URL or editable install in the wrong form

Direct URL references need the name @ https://... form, and editable installs need -e ./path. A bare URL or path on its own line can fail to parse.

How to fix it

Use valid requirement syntax

Fix the operator and remove stray characters. Valid specifiers use ==, >=, <, ~=, etc., with no spaces inside the specifier.

requirements.txt
requests==2.31.0
django>=4.2,<5.0
mypkg @ https://example.com/mypkg-1.0-py3-none-any.whl
-e ./local-package

Find the exact bad line

  1. pip names the file and line number - open it there.
  2. Check for non-ASCII quotes or whitespace pasted from a webpage.
  3. Validate locally with pip install --dry-run -r requirements.txt before pushing.

How to prevent it

  • Lint requirements files in CI before installing.
  • Generate requirements with a tool (pip-compile) instead of hand-editing.
  • Avoid pasting specifiers from rich text that introduces smart quotes.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →