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.
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.
requests==2.31.0
django>=4.2,<5.0
mypkg @ https://example.com/mypkg-1.0-py3-none-any.whl
-e ./local-packageFind the exact bad line
- pip names the file and line number - open it there.
- Check for non-ASCII quotes or whitespace pasted from a webpage.
- Validate locally with
pip install --dry-run -r requirements.txtbefore 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.