Python3.6 pip installation fails under Windows UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd5

For example, pip install flask fails

Exception:
Traceback (most recent call last):
  File "d:\codetest\v\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 0xd5 in position 2: invalid continuation byte

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "d:\codetest\v\lib\site-packages\pip\basecommand.py", line 215, in main
    status = self.run(options, args)
  File "d:\codetest\v\lib\site-packages\pip\commands\install.py", line 342, in run
    prefix=options.prefix_path,
  File "d:\codetest\v\lib\site-packages\pip\req\req_set.py", line 784, in install
    **kwargs
  File "d:\codetest\v\lib\site-packages\pip\req\req_install.py", line 878, in install
    spinner=spinner,
  File "d:\codetest\v\lib\site-packages\pip\utils\__init__.py", line 676, in call_subprocess
    line = console_to_str(proc.stdout.readline())
  File "d:\codetest\v\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 0xd5 in position 2: invalid continuation byte

All solutions on the Internet are nothing more than two

  1. Modify site-packages\pip \ compat_init_.py
  2. change a shell

In the final analysis, it is caused by the default encoding of CMD. There is actually a simple solution.

chcp 65001

After entering the above command, use pip to install it, and you can succeed. You can refer to this solution for other utf8 errors under cmd.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324395547&siteId=291194637