'file:' identifier in '--requirements' argument yields FileNotFoundError
See original GitHub issueDescription
Using a file:
identifier when providing a --requirements|-r
argument results in FileNotFoundError
.
Expected behavior
The file should be found.
Previous versions worked fine. Alternatively, omitting the file:
identifier works.
pip version
21.2.1
Python version
3.9.6
OS
MacOS 10.14
How to Reproduce
-
Create and activate Conda environment with:
conda create -n foo -c conda-forge python=3.9 pip=21.2.1 conda activate foo
-
Create
requirements.txt
:echo "numpy" > requirements.txt
-
Run install command:
pip install -r file:requirements.txt
-
Error.
Output
(foo) bash-3.2$ pip install -r file:requirements.txt
ERROR: Exception:
Traceback (most recent call last):
File "/Users/mfansler/miniconda3/envs/foo/lib/python3.9/site-packages/pip/_internal/cli/base_command.py", line 173, in _main
status = self.run(options, args)
File "/Users/mfansler/miniconda3/envs/foo/lib/python3.9/site-packages/pip/_internal/cli/req_command.py", line 203, in wrapper
return func(self, options, args)
File "/Users/mfansler/miniconda3/envs/foo/lib/python3.9/site-packages/pip/_internal/commands/install.py", line 286, in run
reqs = self.get_requirements(args, options, finder, session)
File "/Users/mfansler/miniconda3/envs/foo/lib/python3.9/site-packages/pip/_internal/cli/req_command.py", line 384, in get_requirements
for parsed_req in parse_requirements(
File "/Users/mfansler/miniconda3/envs/foo/lib/python3.9/site-packages/pip/_internal/req/req_file.py", line 135, in parse_requirements
for parsed_line in parser.parse(filename, constraint):
File "/Users/mfansler/miniconda3/envs/foo/lib/python3.9/site-packages/pip/_internal/req/req_file.py", line 319, in parse
yield from self._parse_and_recurse(filename, constraint)
File "/Users/mfansler/miniconda3/envs/foo/lib/python3.9/site-packages/pip/_internal/req/req_file.py", line 324, in _parse_and_recurse
for line in self._parse_file(filename, constraint):
File "/Users/mfansler/miniconda3/envs/foo/lib/python3.9/site-packages/pip/_internal/req/req_file.py", line 353, in _parse_file
_, content = get_file_content(filename, self._session)
File "/Users/mfansler/miniconda3/envs/foo/lib/python3.9/site-packages/pip/_internal/req/req_file.py", line 518, in get_file_content
resp = session.get(url)
File "/Users/mfansler/miniconda3/envs/foo/lib/python3.9/site-packages/pip/_vendor/requests/sessions.py", line 555, in get
return self.request('GET', url, **kwargs)
File "/Users/mfansler/miniconda3/envs/foo/lib/python3.9/site-packages/pip/_internal/network/session.py", line 454, in request
return super().request(method, url, *args, **kwargs)
File "/Users/mfansler/miniconda3/envs/foo/lib/python3.9/site-packages/pip/_vendor/requests/sessions.py", line 542, in request
resp = self.send(prep, **send_kwargs)
File "/Users/mfansler/miniconda3/envs/foo/lib/python3.9/site-packages/pip/_vendor/requests/sessions.py", line 697, in send
r.content
File "/Users/mfansler/miniconda3/envs/foo/lib/python3.9/site-packages/pip/_vendor/requests/models.py", line 836, in content
self._content = b''.join(self.iter_content(CONTENT_CHUNK_SIZE)) or b''
File "/Users/mfansler/miniconda3/envs/foo/lib/python3.9/site-packages/pip/_vendor/requests/models.py", line 769, in generate
chunk = self.raw.read(chunk_size)
AttributeError: 'FileNotFoundError' object has no attribute 'read'
Code of Conduct
- I agree to follow the PSF Code of Conduct.
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
How do I raise a FileNotFoundError properly? - Stack Overflow
The first is an error code from the errno module (file not found is always errno.
Read more >Python FileNotFoundError: [Errno 2] No such file or directory ...
This error tells you that you are trying to access a file or folder that does not exist. To fix this error, check...
Read more >Python Write to File – Open, Read, Append, and Other File ...
The first parameter of the open() function is file , the absolute or relative path to the file that you are trying to...
Read more >8. Errors and Exceptions — Python 3.11.1 documentation
When an exception occurs, it may have associated values, also known as the exception's arguments. The presence and types of the arguments depend...
Read more >chpldoc — Chapel Documentation 1.19 - chapel-lang.
For more information see the Documenting argument, return, and yield ... mode: `int` :throws FileNotFoundError: If :arg:`name` does not correspond to a file...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
file:requirements.txt
is not a valid URL. The standard (RFC 8089) mandates the URL must starts withfile://
orfile:
+ absolute path. This is neither, so pip treats it as a local relative path and correctly fails.Feel free to submit a PR for better error messages, but this is not a bug.
@DiddiLeija @pradyunsg thanks for addressing this! ❤️