Fix it fast
Most likely: One requirement line is not valid pip syntax: a missing version after ==, smart quotes, mismatched quotes, malformed extras, or version ranges without commas.
1. Confirm this is your error
ERROR: Invalid requirement: 'pip==': Expected end or semicolon (after name and no valid version specifier)
ERROR: Invalid requirement: 'transformers[sentencepiece,torch]<4.26>=4.23.0': Expected end or semicolon (after version specifier)
ERROR: Invalid requirement: '#' 2. Check the cause
python -m pip install -v -r requirements.txt
python -m pip install -v '<requirement>'
python -m pip index versions <package> 3. Apply the safe fix
# Fix common version syntax.
python -m pip install "<package>==<version>"
python -m pip install "<package>>=<min>,<max>"
# Quote extras as one shell argument.
python -m pip install "transformers[sentencepiece,torch]"
# In requirements files, keep one valid requirement per line and use plain ASCII quotes. 4. Verify it works
python -m pip install -r requirements.txt
python -m pip show <package> Don't use unsafe shortcuts
- Do not use smart quotes copied from rich text.
- Do not write
package==without a real version. - Do not combine version constraints without commas, such as
<4.26>=4.23.0.
What This Error Means
Read this as a precise clue about which part of the workflow broke first. Once you know the failing layer, the fix path gets much shorter.
How to Fix It
Fix invalid specifiers:use name==1.2.3 (pin) or name>=1.2,<2 (range).
If you need extras, quote the whole argument:python -m pip install "transformers[sentencepiece,torch]"
Remove or properly comment out lines in requirements files (comments must start with # at the beginning of the line or after whitespace).
If you're unsure what versions exist, search the package index or consult the package's release history, then pin a real version instead of words like latest.
Why It Happens
Usually this comes down to a requirement contains invalid version syntax (for example pip== with no version), a requirement line contains smart quotes (“ / ”) or mismatched quotes (common on Windows shells), a comment or placeholder like #todo is not formatted as a comment in the current context, or version constraints are malformed (for example mixing < and >= without a comma separator).
Verify the Fix
Re-run python -m pip install ... and confirm the Invalid requirement error is gone, and if using a requirements file, run python -m pip install -r requirements.txt and confirm it parses past the previously failing line.
Manual requirements parsing checks
If installing from a file, open it and find the exact line pip reports (run with -v to see more context).
Remove smart quotes and retype quotes using plain ASCII " or '.
If you copied a multiline command, ensure line continuations match your shell.
How pip parses requirement specifiers
This is the part worth understanding if the quick fix did not hold. It explains what pip is trying to do at the moment the error appears.
pip expects requirements in a specific format, such as name, name==version, name>=1.2,<2, or name[extra]==version.
If a requirement contains invalid syntax (like a trailing ==), smart quotes from copy/paste, or a malformed constraint line, pip fails fast with an Invalid requirement error.
Prevent It From Coming Back
Keep requirements files machine-generated when possible (constraints/lock tooling) and avoid manual editing mistakes.
Avoid smart quotes by copying commands from plain text sources.
Prefer one requirement per line with simple specifiers and commas between constraints (e.g. >= and <).
Docs and source code
github.com/pypa/pip/blob/25.3/src/pip/_internal/req/constructors.py
pip parses requirement strings and raises an InstallationError when a requirement can't be parsed ("Invalid requirement: ..."). - GitHub
def install_req_from_req_string(
req_string: str,
comes_from: InstallRequirement | None = None,
isolated: bool = False,
user_supplied: bool = False,
) -> InstallRequirement:
try:
req = get_requirement(req_string)
except InvalidRequirement as exc:
raise InstallationError(f"Invalid requirement: {req_string!r}: {exc}")