iotaledger / pyota-ccurl

C Curl extension for PyOTA
MIT License
3 stars 8 forks source link

UnicodeDecodeError when installing on Windows 10, Python 3.6.4 #22

Open todofixthis opened 6 years ago

todofixthis commented 6 years ago
C:\Python36\Scripts> .\pip.exe install pyota[ccurl]
...
Installing collected packages: pyota-ccurl
  Running setup.py install for pyota-ccurl ... error
Exception:
Traceback (most recent call last):
  File "c:\python36\lib\site-packages\pip\compat\__init__.py", line 73, in console_to_str
    return s.decode(sys.__stdout__.encoding)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x94 in position 90: invalid start byte

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c:\python36\lib\site-packages\pip\basecommand.py", line 215, in main
    status = self.run(options, args)
  File "c:\python36\lib\site-packages\pip\commands\install.py", line 342, in run
    prefix=options.prefix_path,
  File "c:\python36\lib\site-packages\pip\req\req_set.py", line 784, in install
    **kwargs
  File "c:\python36\lib\site-packages\pip\req\req_install.py", line 878, in install
    spinner=spinner,
  File "c:\python36\lib\site-packages\pip\utils\__init__.py", line 676, in call_subprocess
    line = console_to_str(proc.stdout.readline())
  File "c:\python36\lib\site-packages\pip\compat\__init__.py", line 75, in console_to_str
    return s.decode('utf_8')
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x94 in position 90: invalid start byte

See https://pastebin.com/kTAsr3MH for full output.

Note: Works OK on same system with Python 2.7

todofixthis commented 6 years ago

The trouble seems related to differences in the way pip.compat.console_to_str works in different versions of Python:

if sys.version_info >= (3,):
    def console_to_str(s):
        try:
            return s.decode(sys.__stdout__.encoding)
        except UnicodeDecodeError:
            return s.decode('utf_8')

else:
    def console_to_str(s):
        return s

Possible workaround: https://drj11.wordpress.com/2007/05/14/python-how-is-sysstdoutencoding-chosen/

todofixthis commented 6 years ago

lol there's even a PEP for it: https://www.python.org/dev/peps/pep-0528/

todofixthis commented 6 years ago

User was able to work around this issue by explicitly changing the encoding specified in console_to_str() in pip/compat/__init__.py (line 75). (note: pip v9.0.1)

Will look for a more... environmental workaround to recommend in the README (:

chrisoro commented 6 years ago

Yup, I just did chcp in cmd and replaced the 'utf-8' in line 75 with the chcp shown in cmd.

Original issue for pip: https://github.com/pypa/pip/issues/4251