无法运行pip:UnicodeDecodeError

时间:2015-12-23 17:36:10

标签: python numpy encoding pip ubuntu-14.04

我使用pip时遇到了麻烦。例如:

pip install numpy --upgrade

给我以下错误:

Collecting numpy
  Using cached numpy-1.10.2.tar.gz
        Exception:
    Traceback (most recent call last):
      File "/usr/local/lib/python2.7/dist-packages/pip/basecommand.py", line 211, in main
        status = self.run(options, args)
      File "/usr/local/lib/python2.7/dist-packages/pip/commands/install.py", line 305, in run
        wb.build(autobuilding=True)
      File "/usr/local/lib/python2.7/dist-packages/pip/wheel.py", line 705, in build
        self.requirement_set.prepare_files(self.finder)
      File "/usr/local/lib/python2.7/dist-packages/pip/req/req_set.py", line 334, in prepare_files
        functools.partial(self._prepare_file, finder))
      File "/usr/local/lib/python2.7/dist-packages/pip/req/req_set.py", line 321, in _walk_req_to_install
        more_reqs = handler(req_to_install)
      File "/usr/local/lib/python2.7/dist-packages/pip/req/req_set.py", line 505, in _prepare_file
        abstract_dist.prep_for_dist()
      File "/usr/local/lib/python2.7/dist-packages/pip/req/req_set.py", line 123, in prep_for_dist
        self.req_to_install.run_egg_info()
      File "/usr/local/lib/python2.7/dist-packages/pip/req/req_install.py", line 376, in run_egg_info
        self.setup_py, self.name,
      File "/usr/local/lib/python2.7/dist-packages/pip/req/req_install.py", line 347, in setup_py
        import setuptools  # noqa
      File "/usr/local/lib/python2.7/dist-packages/setuptools/__init__.py", line 12, in <module>
        from setuptools.extension import Extension
      File "/usr/local/lib/python2.7/dist-packages/setuptools/extension.py", line 8, in <module>
        from .dist import _get_unpatched
      File "/usr/local/lib/python2.7/dist-packages/setuptools/dist.py", line 19, in <module>
        import pkg_resources
      File "/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 3138, in <module>
        @_call_aside
      File "/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 3124, in _call_aside
        f(*args, **kwargs)
      File "/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 3151, in _initialize_master_working_set
        working_set = WorkingSet._build_master()
      File "/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 652, in _build_master
        ws = cls()
      File "/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 645, in __init__
        self.add_entry(entry)
      File "/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 701, in add_entry
        for dist in find_distributions(entry, True):
      File "/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 2139, in find_on_path
        path_item, entry, metadata, precedence=DEVELOP_DIST
      File "/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 2521, in from_location
        py_version=py_version, platform=platform, **kw
      File "/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 2835, in _reload_version
        md_version = _version_from_file(self._get_metadata(self.PKG_INFO))
      File "/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 2486, in _version_from_file
        line = next(iter(version_lines), '')
      File "/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 2654, in _get_metadata
        for line in self.get_metadata_lines(name):
      File "/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 2030, in get_metadata_lines
        return yield_lines(self.get_metadata(name))
      File "/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 2025, in get_metadata
        metadata = f.read()
      File "/usr/lib/python2.7/codecs.py", line 296, in decode
        (result, consumed) = self._buffer_decode(data, self.errors, final)
    UnicodeDecodeError: 'utf8' codec can't decode byte 0xb6 in position 147: invalid start byte

以下是一些线索:

(i)当我尝试运行Spyder时,我遇到了同样的错误。当我尝试用pip,pandas安装其他软件包时也会出现这种情况。

(ii)我觉得这与默认编码有关,因为sys.getdefaultencoding给了我&#39; ascii&#39;

请注意,如果我在virtualenv中这样做,它会很好用。

我是ubuntu的新手,所以我可能做错了。

设置:python 2.7.6;点7.1.2; ubuntu 14.04.03。

感谢您的帮助。

1 个答案:

答案 0 :(得分:33)

我有同样的问题。就我而言,它来自模块描述中的非标准字符。

我添加了

  

print f.path

脚本中的

  

/usr/local/lib/python2.7/dist-packages/pkg_resources / __初始化__。PY

第2025行之前的

,它允许我识别引发错误的文件。它似乎是文件

  

/usr/lib/pymodules/python2.7/rpl-1.5.5.egg-info

其作者的名称包含ö字符,无法读取。我只是在这个文件中用“Goran”替换了“Göran”,它解决了这个问题。

希望这会有所帮助。