The routine that parses PEP723 metadata opens the script file without specifying the encoding. This causes pip install --requirements-from-script to fail if the script contains characters that fail to decode against the current locale encoding, resulting in a UnicodeDecodeError.
ERROR: Exception:
Traceback (most recent call last):
File "C:\hostedtoolcache\windows\Python\3.14.3\x64\Lib\site-packages\pip\_internal\cli\base_command.py", line 107, in _run_wrapper
status = _inner_run()
File "C:\hostedtoolcache\windows\Python\3.14.3\x64\Lib\site-packages\pip\_internal\cli\base_command.py", line 98, in _inner_run
return self.run(options, args)
~~~~~~~~^^^^^^^^^^^^^^^
File "C:\hostedtoolcache\windows\Python\3.14.3\x64\Lib\site-packages\pip\_internal\cli\req_command.py", line 96, in wrapper
return func(self, options, args)
File "C:\hostedtoolcache\windows\Python\3.14.3\x64\Lib\site-packages\pip\_internal\commands\install.py", line 358, in run
reqs = self.get_requirements(args, options, finder, session)
File "C:\hostedtoolcache\windows\Python\3.14.3\x64\Lib\site-packages\pip\_internal\cli\req_command.py", line 356, in get_requirements
script_metadata = pep723_metadata(script)
File "C:\hostedtoolcache\windows\Python\3.14.3\x64\Lib\site-packages\pip\_internal\req\pep723.py", line 18, in pep723_metadata
script = f.read()
File "C:\hostedtoolcache\windows\Python\3.14.3\x64\Lib\encodings\cp1252.py", line 23, in decode
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
UnicodeDecodeError: 'charmap' codec can't decode byte 0x90 in position 7948: character maps to <undefined>
Description
The routine that parses PEP723 metadata opens the script file without specifying the encoding. This causes pip install --requirements-from-script to fail if the script contains characters that fail to decode against the current locale encoding, resulting in a UnicodeDecodeError.
Expected behavior
The spec states that "Tools reading embedded metadata MAY respect the standard Python encoding declaration. If they choose not to do so, they MUST process the file as UTF-8." I therefore believe that specifying the UTF-8 encoding if sufficient to become compliant.
pip version
26.0.1
Python version
any <= 3.14
OS
mostly likely to occur on windows
How to Reproduce
Output
Code of Conduct