pip UnicodeDecodeError:'utf8'编解码器无法解码字节 [英] pip UnicodeDecodeError: 'utf8' codec can't decode byte

查看:226
本文介绍了pip UnicodeDecodeError:'utf8'编解码器无法解码字节的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我运行pip,无论我传递给pip的标志是什么,我总是会遇到以下错误:

I run pip, and I always get the following error, no matter what flags I pass to pip:

$ pip --version
Traceback (most recent call last):
    [...irrelevant details omitted...]
      File "/usr/lib64/python2.7/codecs.py", line 314, in decode
    (result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf8' codec can't decode byte 0xf6 in position 203: invalid start byte

这是怎么回事?我该如何解决?

What's going on? How do I fix this?

我安装了pip版本8.0.2.更改或清除LANGLC_ALL环境变量无济于事.我必须在这里阅读其他十几个问题,但我一直在努力寻找能够清楚说明问题是什么或如何解决的任何信息.

I have pip version 8.0.2 installed. Changing or clearing the LANG and LC_ALL environment variables doesn't help. I must have read a dozen other questions here but I'm struggling to find anything that provides a clear indication of what the problem is or how to fix it.

推荐答案

发生了什么事情

pip有问题.如果任何已安装的Python系统库在库说明中包含非ASCII字符,则可能会崩溃.

What's going on

pip is buggy. It can crashes if any installed Python system library has a non-ASCII character in the library description.

错误消息的相关部分是这样的:

The relevant part of the error message is this:

UnicodeDecodeError: 'utf8' codec can't decode byte ...

特定的字节值并不重要.崩溃是由存储Python软件包的系统目录中.egg-info文件中的某种非ASCII字符触发的(例如/usr/lib/python2.7/site-packages). pip尝试解析所有这些文件,当遇到某些非ASCII字符时,它倒下并死掉.

The specific byte value isn't important. The crash is triggered by a certain kind of non-ASCII character in a .egg-info file in the system directory where Python packages are stored (e.g., /usr/lib/python2.7/site-packages). pip tries to parse all of those files, and when it encounters certain non-ASCII characters, it falls over and dies.

有两种选择:

  1. 正确的解决方法:将pip更新到最新版本.这样可以修复该错误.

  1. The right fix: Update pip to the latest version. This fixes the bug.

纠缠::删除触发pip崩溃的令人讨厌的Python库程序包.这就需要您弄清楚哪个Python库包负责.不幸的是,pip并没有帮助您解决这个问题,因此您将不得不进行一些摸索以找出答案-请参阅下一节.

The kludge: Remove the offending Python library package that triggers pip to crash. That requires you to figure out which Python library package is responsible; unfortunately, pip doesn't give you much help figuring that out, so you're going to have to do some sleuthing to figure that out -- see the next section.

显然,前一种方法更可取...但是如果由于某些原因您不能升级pip,我将介绍如何采用第二种方法.

Obviously, the former option is preferable... but if for some reason you cannot upgrade pip, I'll describe how to follow the second approach.

在这里,您可以检查Python系统软件包并缩小可能导致pip崩溃的原因.我们将在Python site-packages/目录中查找具有非ASCII字符的任何*.egg-info文件.试试这个:

Here's how you can check your Python system packages and narrow down which one might be responsible for pip's crashes. We're going to look for any *.egg-info file in the Python site-packages/ directory that has a non-ASCII character. Try this:

cd /usr/lib/python2.7/site-packages
LANG=ascii grep -P  '[[:^ascii:]]' *.egg-info 2>/dev/null

(这需要GNU grep.)浏览找到的匹配项.检查每个文件以查看其是否包含与错误消息匹配的非ASCII字符.

(This requires GNU grep.) Look through the matches it finds. Check each file to see if it contains a non-ASCII character that matches the error message.

在我的情况下,错误消息提到了can't decode byte 0xf6,因此我们将查找包含0xf6字节的文件.我们可以使用十六进制转储实用程序检查每个匹配的文件.我喜欢使用hexdump -C.

In my case, the error message mentioned can't decode byte 0xf6, so we're going to look for the file that contains a 0xf6 byte. We can inspect each matching file using a hex dump utility; I like to use hexdump -C.

要找到匹配项,您可能需要检查Python软件包的其他位置,例如/usr/lib64/python2.7/site-packages/usr/local/lib/python2.7/site-packages等.

To find the match, you might need to check other locations for Python packages, e.g., /usr/lib64/python2.7/site-packages, /usr/local/lib/python2.7/site-packages, and so on.

一旦找到导致问题的Python程序包,就可以尝试删除该库(如果它不是必需的程序包).

Once you find the Python package that is causing the problems, you can try removing that library (if it is not an essential package).

在较旧的系统上,如果您当前的路径或用户名包含任何非ASCII字符,也可能触发此错误.

On older systems, this error could also be triggered if your current path or your username contains any non-ASCII characters.

有人报告说,他们通过清除LC_ALLLANG环境变量或将它们设置为不同的设置(例如export LC_ALL="en_US.UTF-8" LANG="en_US.UTF-8")而取得了成功.不过,这对我没有帮助.

Some people reported that they had success by clearing the LC_ALL and LANG environment variables, or by setting them to different settings, such as export LC_ALL="en_US.UTF-8" LANG="en_US.UTF-8". This didn't help for me, though.

我认为有帮助的参考文献

References that I found helpful:

通过pip install UnicodeDecodeError

这篇关于pip UnicodeDecodeError:'utf8'编解码器无法解码字节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆