Win10上Python3通过pip install Twisted安装时出现UnicodeDecodeError

Posted 疾速蜗牛

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Win10上Python3通过pip install Twisted安装时出现UnicodeDecodeError相关的知识,希望对你有一定的参考价值。

pip install Twisted

报错:

C:\Windows\system32>pip install Twisted
Collecting Twisted
  Using cached Twisted-17.9.0.tar.bz2
Requirement already satisfied: zope.interface>=4.0.2 in c:\users\xxx\appdata\local\programs\python\python36\lib\site-packages (from Twisted)
Requirement already satisfied: constantly>=15.1 in c:\users\xxx\appdata\local\programs\python\python36\lib\site-packages (from Twisted)
Requirement already satisfied: incremental>=16.10.1 in c:\users\xxx\appdata\local\programs\python\python36\lib\site-packages (from Twisted)
Requirement already satisfied: Automat>=0.3.0 in c:\users\xxx\appdata\local\programs\python\python36\lib\site-packages (from Twisted)
Requirement already satisfied: hyperlink>=17.1.1 in c:\users\xxx\appdata\local\programs\python\python36\lib\site-packages (from Twisted)
Requirement already satisfied: setuptools in c:\users\xxx\appdata\local\programs\python\python36\lib\site-packages (from zope.interface>=4.0.2->Twisted)
Requirement already satisfied: attrs in c:\users\xxx\appdata\local\programs\python\python36\lib\site-packages (from Automat>=0.3.0->Twisted)
Requirement already satisfied: six in c:\users\xxx\appdata\local\programs\python\python36\lib\site-packages (from Automat>=0.3.0->Twisted)
Requirement already satisfied: idna>=2.5 in c:\users\xxx\appdata\local\programs\python\python36\lib\site-packages (from hyperlink>=17.1.1->Twisted)
Installing collected packages: Twisted
  Running setup.py install for Twisted ... error
Exception:
Traceback (most recent call last):
  File "c:\users\xxx\appdata\local\programs\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 0xd5 in position 2: invalid continuation byte

During handling of the above exception, another exception occurred:

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

解决方案:

打开"c:\users\xxx\appdata\local\programs\python\python36\lib\site-packages\pip\compat\__init__.py",定位至75行,修改return s.decode(‘utf-8‘)为return s.decode(‘cp936‘)

原因: 
编码问题,虽然py3统一用utf-8了。但win下的终端显示用的还是gbk编码。

以上是关于Win10上Python3通过pip install Twisted安装时出现UnicodeDecodeError的主要内容,如果未能解决你的问题,请参考以下文章

Win10 安装 Python3 (上)

win7下python2.7怎么安装pip

win下通过pip安装TensorFlow

win7的python3.5安装numpy包

python3_pip_window10_"pymysql install"

Tensorflow在win10下的安装(CPU版本)