Skip to content
This repository has been archived by the owner on Jun 7, 2023. It is now read-only.

UnicodeDecodeError when installing on Windows 10, Python 3.6.4 #22

Open
todofixthis opened this issue Jan 30, 2018 · 4 comments
Open

UnicodeDecodeError when installing on Windows 10, Python 3.6.4 #22

todofixthis opened this issue Jan 30, 2018 · 4 comments
Assignees
Labels

Comments

@todofixthis
Copy link
Contributor

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 todofixthis self-assigned this Jan 30, 2018
@todofixthis
Copy link
Contributor Author

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
Copy link
Contributor Author

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

@todofixthis
Copy link
Contributor Author

todofixthis commented Jan 30, 2018

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
Copy link

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: pypa/pip#4251

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants