UnicodeDecodeError:' utf8'编解码器不能解码位置661中的字节0x92:无效的起始字节

时间:2016-02-16 08:37:47

标签: python python-2.7 virtualenv

我试图通过从https://pip.pypa.io下载get-pip.py来安装python 2.7.2上的最新pip。 我使用此语句从Windows命令提示符运行该文件

c:\Python27>pip

我还尝试按照http://arunrocks.com/guide-to-install-python-or-pip-on-windows/中的步骤操作。 但它不起作用。它仍然提供相同的错误追溯。

有没有人有任何分享的提示?我使用的是Windows 7(64位),python 2.7.2和EPD 7.2-2

错误追溯:

Traceback (most recent call last):
  File "C:\Python27\Scripts\pip-script.py", line 9, in <module>
    load_entry_point('pip==8.0.2', 'console_scripts', 'pip')()
  File "C:\Python27\lib\site-packages\pkg_resources.py", line 337, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "C:\Python27\lib\site-packages\pkg_resources.py", line 2279, in load_entry_point
    return ep.load()
  File "C:\Python27\lib\site-packages\pkg_resources.py", line 1989, in load
    entry = __import__(self.module_name, globals(),globals(), ['__name__'])
  File "C:\Python27\lib\site-packages\pip-8.0.2-py2.7.egg\pip\__init__.py", line 13, in <module>
    from pip.utils import get_installed_distributions, get_prog
  File "C:\Python27\lib\site-packages\pip-8.0.2-py2.7.egg\pip\utils\__init__.py", line 26, in <module>
    from pip._vendor import pkg_resources
  File "C:\Python27\lib\site-packages\pip-8.0.2-py2.7.egg\pip\_vendor\pkg_resources\__init__.py", line 3130, in <module>
    @_call_aside
  File "C:\Python27\lib\site-packages\pip-8.0.2-py2.7.egg\pip\_vendor\pkg_resources\__init__.py", line 3116, in _call_aside
    f(*args, **kwargs)
  File "C:\Python27\lib\site-packages\pip-8.0.2-py2.7.egg\pip\_vendor\pkg_resources\__init__.py", line 3143, in _initialize_master_working_set
    working_set = WorkingSet._build_master()
  File "C:\Python27\lib\site-packages\pip-8.0.2-py2.7.egg\pip\_vendor\pkg_resources\__init__.py", line 633, in _build_master
    ws = cls()
  File "C:\Python27\lib\site-packages\pip-8.0.2-py2.7.egg\pip\_vendor\pkg_resources\__init__.py", line 626, in __init__
    self.add_entry(entry)
  File "C:\Python27\lib\site-packages\pip-8.0.2-py2.7.egg\pip\_vendor\pkg_resources\__init__.py", line 682, in add_entry
    for dist in find_distributions(entry, True):
  File "C:\Python27\lib\site-packages\pip-8.0.2-py2.7.egg\pip\_vendor\pkg_resources\__init__.py", line 2120, in find_on_path
    path_item, entry, metadata, precedence=DEVELOP_DIST
  File "C:\Python27\lib\site-packages\pip-8.0.2-py2.7.egg\pip\_vendor\pkg_resources\__init__.py", line 2510, in from_location
    py_version=py_version, platform=platform, **kw
  File "C:\Python27\lib\site-packages\pip-8.0.2-py2.7.egg\pip\_vendor\pkg_resources\__init__.py", line 2827, in _reload_version
    md_version = _version_from_file(self._get_metadata(self.PKG_INFO))
  File "C:\Python27\lib\site-packages\pip-8.0.2-py2.7.egg\pip\_vendor\pkg_resources\__init__.py", line 2475, in _version_from_file
    line = next(iter(version_lines), '')
  File "C:\Python27\lib\site-packages\pip-8.0.2-py2.7.egg\pip\_vendor\pkg_resources\__init__.py", line 2643, in _get_metadata
    for line in self.get_metadata_lines(name):
  File "C:\Python27\lib\site-packages\pip-8.0.2-py2.7.egg\pip\_vendor\pkg_resources\__init__.py", line 2011, in get_metadata_lines
    return yield_lines(self.get_metadata(name))
  File "C:\Python27\lib\site-packages\pip-8.0.2-py2.7.egg\pip\_vendor\pkg_resources\__init__.py", line 2006, in get_metadata
    metadata = f.read()
  File "C:\Python27\lib\codecs.py", line 296, in decode
    (result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf8' codec can't decode byte 0x92 in position 661: invalid start byte

1 个答案:

答案 0 :(得分:-1)

根据上述评论,某些已安装的库可能存在鸡蛋信息问题。

快速找出哪一个是编辑您的违规 init .py并根据以下内容添加打印声明:

def get_metadata(self, name):
    with io.open(self.path, encoding='utf-8') as f:
        if name=='PKG-INFO':
            print self.path  #ADD THIS

在我的案例中(EPD python),它将PySide-1.1.0-3.egg-info识别为问题......谁知道原因。删除那个egg-info让我超越了错误。长期解决方案是寻找正确或更新的包。