安装scrapy报错

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc8 in position 3: invalid continuation byte

python 3.6;安装scrapy框架 ;报错;UnicodeDecodeError:'utf-8' codec can't decode byte 0xc8 in position 3: invalid continuation byte

Exception:

Traceback (most recent call last):
  File "d:\program files (x86)\python\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 0xc8 in position 3: invalid continuation byte


During handling of the above exception, another exception occurred:


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

根据trackback信息找到文件d:\program files (x86)\python\python36\lib\site-packages\pip\compat\__init__.py

相关代码为

 

sys.__stdout__.encoding指的是什么呢?根据 'utf-8' codec can't decode byte 0xc8 in position 3: invalid continuation byte

应该是utf-8

方法一:

我们把73行的sys.__stdout__.encoding改为‘gbk’ 就万事大吉了。

具体为什么是‘gbk ’ 因为被‘gbk’虐太多次了一有问题基本上就是这个玩意,也可能是Windows系统的原因

ctrl+s保存下

重新输入安装命令pip install Scrapy

安静安静

安装成功后,我选择把sys.__stdout__.encoding改回去(虽然以后都在win下弄,但还是小心点好。。),小心翼翼的闭嘴

方法二(未测试):

import sys

sys.setdefaultencoding('gbk')

#把sys.__stdout__.encoding改成‘gbk’ ?

posted @ 2018-05-18 10:28  诛仙物语  阅读(232)  评论(0编辑  收藏  举报