Python PIP UnicodeDecodeError 错误

    在win10上通过pip安装  PyYAML bcolz时会出现UnicodeDecodeError ,使用 chcp 65001也不起作用

 C:\Users\jli>pip --version
pip 9.0.1 from C:\DevApp\Anaconda3\envs\rqtest\lib\site-packages (python 3.6)

   这gitbub上已经有fix了,但似乎还没有merge到 pip 9.0.1,  找到pip安装目录,在pip\compat\__init__.py", line 73   替换 console_to_str

,新的代码为


 def subprocess_encoding():
        if WINDOWS:
            if sys.version_info >= (3, 6):
                return "oem"
            # Prior to Python 3.6, sys.__stdout__ is opened
            # with the OEM code page (at least in the console
            # interpreter, which is what pip uses). This changed
            # in Python 3.6 to be UTF8, but we don't care as we
            # use the explicit "oem" encoding in that case via
            # the code above
            return sys.__stdout__.encoding
        else:
            import locale
            # Note that the use of getpreferredencoding here calls
            # setlocale, which isn't thread safe. This is OK, as we
            # never call this code in a multi-threaded context.
            # If thread safety was important, we could call
            # getpreferredencoding(False), but there are apparently
            # some systems where that will not give the correct answer.
            #
            # We fall back to UTF8 if locale can't provide an answer,
            # as UTF8 is the most common encoding used nowadays.
            return locale.getpreferredencoding() or "utf-8"

    def console_to_str(s):
        return s.decode(subprocess_encoding(), errors="replace")






 C:\Users\jli>pip install bcolz
Collecting bcolz
  Using cached bcolz-1.1.2.tar.gz
Exception:
Traceback (most recent call last):
  File "C:\DevApp\Anaconda3\envs\rqtest\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 0xb6 in position 32: invalid start byte

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\DevApp\Anaconda3\envs\rqtest\lib\site-packages\pip\basecommand.py", line 215, in main
    status = self.run(options, args)
  File "C:\DevApp\Anaconda3\envs\rqtest\lib\site-packages\pip\commands\install.py", line 335, in run
    wb.build(autobuilding=True)
  File "C:\DevApp\Anaconda3\envs\rqtest\lib\site-packages\pip\wheel.py", line 749, in build
    self.requirement_set.prepare_files(self.finder)
  File "C:\DevApp\Anaconda3\envs\rqtest\lib\site-packages\pip\req\req_set.py", line 380, in prepare_files
    ignore_dependencies=self.ignore_dependencies))
  File "C:\DevApp\Anaconda3\envs\rqtest\lib\site-packages\pip\req\req_set.py", line 634, in _prepare_file
    abstract_dist.prep_for_dist()
  File "C:\DevApp\Anaconda3\envs\rqtest\lib\site-packages\pip\req\req_set.py", line 129, in prep_for_dist
    self.req_to_install.run_egg_info()
  File "C:\DevApp\Anaconda3\envs\rqtest\lib\site-packages\pip\req\req_install.py", line 439, in run_egg_info
    command_desc='python setup.py egg_info')
  File "C:\DevApp\Anaconda3\envs\rqtest\lib\site-packages\pip\utils\__init__.py", line 676, in call_subprocess
    line = console_to_str(proc.stdout.readline())
  File "C:\DevApp\Anaconda3\envs\rqtest\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 0xb6 in position 32: invalid start byte



  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值