python3 使用 pip 安装时的UnicodeDecodeError问题

      我使用pip安装flask框架, 其中在安装MarkupSafe这一模块时遇到了问题,报错如下

Exception:
Traceback (most recent call last):
  File "C:\Users\Lixin\AppData\Local\Programs\Python\Python36-32\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 "C:\Users\Lixin\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pip\basecommand.py", line 215, in main
    status = self.run(options, args)
  File "C:\Users\Lixin\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pip\commands\install.py", line 342, in run
    prefix=options.prefix_path,
  File "C:\Users\Lixin\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pip\req\req_set.py", line 784, in install
    **kwargs
  File "C:\Users\Lixin\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pip\req\req_install.py", line 878, in install
    spinner=spinner,
  File "C:\Users\Lixin\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pip\utils\__init__.py", line 676, in call_subprocess
    line = console_to_str(proc.stdout.readline())
  File "C:\Users\Lixin\AppData\Local\Programs\Python\Python36-32\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

     网上也有很多类似的问题,但都是基于python2.x来解决的。我知道导致这一问题的原因就是路径中出现了中文,而windows系统是用GBK编码的,因此我尝试将pip\compat\__init__.py中出现问题的那一句(也就是报错信息中我用红色标注的)'utf-8'改成‘gbk',问题就解决了。

     顺便一提,当安装错误,我重启电脑再次安装时,会提示模块已经安装,这时安装上去的代码是不全的,使用时肯定会出错。需要你先卸载该模块再重新按照改正后的方法安装

你可能感兴趣的:(python3 使用 pip 安装时的UnicodeDecodeError问题)