pipenv install error UnicodeDecodeError: 'utf8' codec can't decode byte 0xb4 in position

环境

  • win7
  • python 2.7.14 32bit

问题

在使用 pipenv 初始化安装过程时,遇到编码问题,错误如下

λ pipenv install
Creating a virtualenv for this project...
Pipfile: F:\Code\AuotSystraceAnalysis\Pipfile
Using c:\python27\python.exe (None) to create virtualenv...
Traceback (most recent call last):
  File "c:\python27\lib\runpy.py", line 174, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "c:\python27\lib\runpy.py", line 72, in _run_code
    exec code in run_globals
  File "C:\Python27\Scripts\pipenv.exe\__main__.py", line 9, in 
  File "c:\python27\lib\site-packages\pipenv\vendor\click\core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "c:\python27\lib\site-packages\pipenv\vendor\click\core.py", line 717, in main
    rv = self.invoke(ctx)
  File "c:\python27\lib\site-packages\pipenv\vendor\click\core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "c:\python27\lib\site-packages\pipenv\vendor\click\core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "c:\python27\lib\site-packages\pipenv\vendor\click\core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "c:\python27\lib\site-packages\pipenv\vendor\click\decorators.py", line 64, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
  File "c:\python27\lib\site-packages\pipenv\vendor\click\core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "c:\python27\lib\site-packages\pipenv\vendor\click\decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "c:\python27\lib\site-packages\pipenv\cli\command.py", line 254, in install
    editable_packages=state.installstate.editables,
  File "c:\python27\lib\site-packages\pipenv\core.py", line 1741, in do_install
    pypi_mirror=pypi_mirror,
  File "c:\python27\lib\site-packages\pipenv\core.py", line 574, in ensure_project
    pypi_mirror=pypi_mirror,
  File "c:\python27\lib\site-packages\pipenv\core.py", line 506, in ensure_virtualenv
    python=python, site_packages=site_packages, pypi_mirror=pypi_mirror
  File "c:\python27\lib\site-packages\pipenv\core.py", line 929, in do_create_virtualenv
    combine_stderr=False, block=True, nospin=True, env=pip_config,
  File "c:\python27\lib\site-packages\pipenv\vendor\vistir\misc.py", line 285, in run
    _env = {fs_encode(k): fs_encode(v) for k, v in os.environ.items()}
  File "c:\python27\lib\site-packages\pipenv\vendor\vistir\misc.py", line 285, in 
    _env = {fs_encode(k): fs_encode(v) for k, v in os.environ.items()}
  File "c:\python27\lib\site-packages\pipenv\vendor\vistir\misc.py", line 397, in to_bytes
    return string.decode("utf-8").encode(encoding, errors)
  File "c:\python27\lib\encodings\utf_8.py", line 16, in decode
    return codecs.utf_8_decode(input, errors, True)
UnicodeDecodeError: 'utf8' codec can't decode byte 0xb4 in position 671: invalid start byte

分析

从错误内容看,是编码方式问题,不确定是否中文问题影响,错误内容在
c:\python27\lib\site-packages\pipenv\vendor\vistir\misc.py的397行,return string.decode("utf-8").encode(encoding, errors) 这句错误,也就是用 ‘utf-8’ 解码方式报错,这里将其改为 “gbk” 尝试 pass

  File "c:\python27\lib\site-packages\pipenv\vendor\vistir\misc.py", line 397, in to_bytes
    return string.decode("utf-8").encode(encoding, errors)

解决方法

将 c:\python27\lib\site-packages\pipenv\vendor\vistir\misc.py 文件397 的 ‘utf-8’ 改为 ‘gbk’ 方式,Ok

pipenv install error UnicodeDecodeError: 'utf8' codec can't decode byte 0xb4 in position_第1张图片

pass
在这里插入图片描述

你可能感兴趣的:(排错)