-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pip
fails to parse install_requires
containing local wheel with spaces in path
#13139
Comments
Two things:
Python 3.12.4 (main, Jun 21 2024, 18:39:32) [GCC 13.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from packaging.requirements import Requirement
>>> Requirement("pipefunc-0.46.0-py3-none-any.whl @ file://$(pwd)/my folder/pipefunc-0.46.0-py3-none-any.whl")
Traceback (most recent call last):
File "/home/ichard26/.local/lib/python3.12/site-packages/packaging/requirements.py", line 36, in __init__
parsed = _parse_requirement(requirement_string)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/ichard26/.local/lib/python3.12/site-packages/packaging/_parser.py", line 62, in parse_requirement
return _parse_requirement(Tokenizer(source, rules=DEFAULT_RULES))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/ichard26/.local/lib/python3.12/site-packages/packaging/_parser.py", line 80, in _parse_requirement
url, specifier, marker = _parse_requirement_details(tokenizer)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/ichard26/.local/lib/python3.12/site-packages/packaging/_parser.py", line 113, in _parse_requirement_details
marker = _parse_requirement_marker(
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/ichard26/.local/lib/python3.12/site-packages/packaging/_parser.py", line 145, in _parse_requirement_marker
tokenizer.raise_syntax_error(
File "/home/ichard26/.local/lib/python3.12/site-packages/packaging/_tokenizer.py", line 167, in raise_syntax_error
raise ParserSyntaxError(
packaging._tokenizer.ParserSyntaxError: Expected end or semicolon (after URL and whitespace)
pipefunc-0.46.0-py3-none-any.whl @ file://$(pwd)/my folder/pipefunc-0.46.0-py3-none-any.whl
~~~~~~~~~~~~~~~~~^
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/ichard26/.local/lib/python3.12/site-packages/packaging/requirements.py", line 38, in __init__
raise InvalidRequirement(str(e)) from e
packaging.requirements.InvalidRequirement: Expected end or semicolon (after URL and whitespace)
pipefunc-0.46.0-py3-none-any.whl @ file://$(pwd)/my folder/pipefunc-0.46.0-py3-none-any.whl According to the dependency specifier specification, whitespace is used to denote the end of an URL specifier:
You will need to escape the space using percent-encoding.
I will note that the bare URL syntax is a pip extension. It's not part of the specification, and pip will handle unescaped spaces just fine (as long as it's passed as a single argument, aka with quotes). |
Thank you so much @ichard26, using |
I just made an edit with a callout that passing the bare URL is a pip feature, not defined by a standard, so that's why you see differing behaviour w/ whitespace FYI. I'm glad that I could help! |
Closes #211 Thanks to @ichard26 in pypa/pip#13139 (comment) cc @dustin-dawind
* Replace whitespace in `file://` with `%20` Closes #211 Thanks to @ichard26 in pypa/pip#13139 (comment) cc @dustin-dawind * Fix editable install for whl and zip * Fix typo in test_split_path_and_extras * Use manual replace instead of quote * use `urllib.request.pathname2url` Co-authored-by: Richard Si <sichard26@gmail.com> * fix import of urllib * fix double `file:` * Add missing // * Just use `.replace(" ", "%20")` again --------- Co-authored-by: Richard Si <sichard26@gmail.com>
Description
pip
fails to install a package when itssetup.py
'sinstall_requires
contains a local wheel file path that includes spaces. The error indicates thatpip
is unable to correctly parse the requirement string, specifically it has trouble with the "Expected end or semicolon (after URL and whitespace)" part.I run into this problem in the unidep package (basnijholt/unidep#211).
Expected behavior
pip
should correctly parse theinstall_requires
and install the local wheel, even if its path contains spaces.pip version
24.3.1
Python version
3.13.1
OS
macos and ubuntu verified
How to Reproduce
Setup:
Command:
pip install --verbose .
Output
pip
fails with the following error:Code of Conduct
The text was updated successfully, but these errors were encountered: