本文介绍了无法运行pip:UnicodeDecodeError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我有麻烦使用点。例如: pip install numpy --upgrade 给我以下错误: 收集numpy 使用缓存numpy-1.10.2.tar.gz 异常:追溯(最近调用最后):文件/usr/local/lib/python2.7/dist-packages/pip/ basecommand.py,第211行,主要 status = self.run(options,args)文件/usr/local/lib/python2.7/dist-packages/pip/commands/install .py,第305行,运行 wb.build(autobuilding = True)文件/usr/local/lib/python2.7/dist-packages/pip/wheel.py,行705,in build self.requirement_set.prepare_files(self.finder)文件/usr/local/lib/python2.7/dist-packages/pip/req/req_set.py,第334行,在prepare_files functools.partial(self._prepare_file,finder))文件/usr/local/lib/python2.7/dist-packages/pip/req/req_set.py,第321行在_walk_req_to_install 中more_reqs = handler(req_to_install)文件/usr/local/lib/python2.7/dist-packages/pip/req/req_set.py,第505行,在_prepare_file abstract_dist.prep_for_dist() 文件/usr/local/lib/python2.7/dist-packages/pip/req/req_set.py,第123行,在prep_for_dist self.req_to_install.run_egg_info()文件/usr/local/lib/python2.7/dist-packages/pip/req/req_install.py,第376行,在run_egg_info self.setup_py,self.name,文件/ usr / local / lib / python2.7 / dist-packages / pip / req / req_install.py,第347行,在setup_py 中导入setuptools#noqa 文件/ usr / local / lib / python2 .7 / dist-packages / setuptools / __ init__.py,第12行在< module> 从setuptools.extension import扩展文件/usr/local/lib/python2.7/dist-packages/setuptools/extension.py,第8行在< module> from .dist import _get_unpatched 文件/usr/local/lib/python2.7/dist-packages/setuptools/dist.py,第19行,< module> import pkg_resources 文件/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py,第3138行在< module> @_call_aside 文件/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py,第3124行,_call_aside f(* args,** kwargs )文件/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py,第3151行,在_initialize_master_working_set working_set = WorkingSet._build_master()文件/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py,第652行,_build_master ws = cls()文件/ usr / local / lib / python2.7 / dist-packages / pkg_resources / __ init__.py,第645行,__init__ self.add_entry(entry)文件/usr/local/lib/python2.7/dist-packages /pkg_resources/__init__.py,第701行,add_entry for find在find_distributions中(entry,True):文件/usr/local/lib/python2.7/dist-packages/pkg_resources/ __init__.py,第2139行,find_on_path path_item,entry,metadata,precedence = DEVELOP_DIST 文件/ usr / local / lib / python2.7 / dist-packages / pkg_resources / __ init__.py,第2521行,from_location py_version = py_version,platform = platform,** kw 文件/ usr / local / lib / python2 7 / dist-packages / pkg_resources / __ init__.py,第2835行,_reload_version md_version = _version_from_file(self._get_metadata(self.PKG_INFO))文件/ usr / local / lib / python2 7 / dist-packages / pkg_resources / __ init__.py,第2486行_version_from_file line = next(iter(version_lines),'')文件/usr/local/lib/python2.7 /dist-packages/pkg_resources/__init__.py,第2654行,在_get_metadata for self.get_metadata_lines(name)中:文件/usr/local/lib/python2.7/dist- package / pkg_resources / __ init__.py,第2030行,get_metadata_lines 返回yield_lines(self.get_metadata(name))文件/usr/local/lib/python2.7/dist-packages/pkg_resources /__init__.py,第2025行,get_metadata metadata = f.read()文件/usr/lib/python2.7/codecs.py,第296行,解码(result,consumption)= self._buffer_decode(data,self.errors,final) UnicodeDecodeError: utf8'编解码器无法解码位置147的字节0xb6:无效的起始字节 这里有一些线索: (i)当我尝试运行Spyder时,我有相同的错误。当我尝试安装其他软件包,例如熊猫,熊猫时也会出现。 (ii)我有这种感觉,这与默认编码有关,因为sys.getdefaultencoding给了我'ascii' 注意,如果我在一个virtualenv中这样做,它的效果很好。 我是ubuntu的新手,所以我可能做错了。 设置:python 2.7.6;点7.1.2; ubuntu 14.04.03。 感谢您的帮助。解决方案我有同样的问题。在我的情况下,它来自模块描述中的非标准字符。 我添加了一个在脚本中 /usr/local/lib/python2.7/dist-packages/pkg_resources / __ init __。py 在2025行之前,这使我能够识别正在提出错误的文件。它似乎是文件其作者的名称包含ö字符,无法读取。我只是在这个文件中用Gorran替换了Gorran,并解决了这个问题。 希望这有帮助。 I have trouble using pip. For example: pip install numpy --upgradeGives me the following error: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 byteHere are some clues:(i) I have the same error when I try to run Spyder. It also appears when I try to to install other packages wtih pip, pandas for example. (ii) I have the feeling, that this is related to the default encoding since sys.getdefaultencoding gives me 'ascii' Note that it works well if I do it in a virtualenv. I'm new to ubuntu so I might have done someting wrong. Setup: python 2.7.6; pip 7.1.2; ubuntu 14.04.03.Thank you for your help. 解决方案 I had the same issue. In my case, it comes from a non-standard character in a module description.I added a in the scriptbefore line 2025, which allowed me to identify the file which was raising an error. It appeared to be the filewhose author has a name containing the ö character, which can not be read. I simply replaced the "Göran" with "Goran" in this file and it fixed the problem.hope this helps. 这篇关于无法运行pip:UnicodeDecodeError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-15 22:29