Python 如何修复“导入错误:无法导入名称 IncompleteRead”?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27341064/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I fix 'ImportError: cannot import name IncompleteRead'?
提问by Martin Thoma
When I try to install anything with pip
or pip3
, I get:
当我尝试使用pip
或安装任何东西时pip3
,我得到:
$ sudo pip3 install python3-tk
Traceback (most recent call last):
File "/usr/bin/pip3", line 9, in <module>
load_entry_point('pip==1.5.6', 'console_scripts', 'pip3')()
File "/usr/lib/python3/dist-packages/pkg_resources.py", line 356, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/usr/lib/python3/dist-packages/pkg_resources.py", line 2476, in load_entry_point
return ep.load()
File "/usr/lib/python3/dist-packages/pkg_resources.py", line 2190, in load
['__name__'])
File "/usr/lib/python3/dist-packages/pip/__init__.py", line 61, in <module>
from pip.vcs import git, mercurial, subversion, bazaar # noqa
File "/usr/lib/python3/dist-packages/pip/vcs/mercurial.py", line 9, in <module>
from pip.download import path_to_url
File "/usr/lib/python3/dist-packages/pip/download.py", line 25, in <module>
from requests.compat import IncompleteRead
ImportError: cannot import name 'IncompleteRead'
I have a Ubuntu 14.10 system.
我有一个 Ubuntu 14.10 系统。
How can I fix this problem?
我该如何解决这个问题?
采纳答案by thomas.mc.work
While this previous answermight be the reason, this snipped worked for me as a solution (in Ubuntu 14.04
):
虽然这个先前的答案可能是原因,但这个剪辑对我来说是一个解决方案(在Ubuntu 14.04
):
First remove the package from the package manager:
首先从包管理器中删除包:
# apt-get remove python-pip
And then install the latest version by side:
然后并排安装最新版本:
# easy_install pip
(thanks to @Aufziehvogel, @JunchaoGu)
(感谢@Aufziehvogel、@JunchaoGu)
回答by Martin Thoma
The problem is the Python module requests
. It can be fixed by
问题是 Python 模块requests
。它可以通过
$ sudo apt-get purge python-requests
[now requests and pip gets deinstalled]
$ sudo apt-get install python-requests python-pip
If you have this problem with Python 3, you have to write python3
instead of python
.
如果您在 Python 3 中遇到此问题,则必须编写python3
而不是python
.
回答by Aufziehvogel
This problem is caused by a mismatch between your pip installation and your requests installation.
此问题是由 pip 安装和 requests 安装之间的不匹配引起的。
As of requests version 2.4.0 requests.compat.IncompleteRead
has been removed. Older versions of pip, e.g. from July 2014, still relied on IncompleteRead
. In the current versionof pip, the import of IncompleteRead
has been removed.
截至请求版本 2.4.0requests.compat.IncompleteRead
已被删除。旧版本的 pip,例如从 2014 年 7 月开始,仍然依赖于IncompleteRead
. 在当前版本的 pip 中,IncompleteRead
已删除的导入。
So the one to blame is either:
因此,应该归咎于:
- requests, for removing public API too quickly
- Ubuntu for updating pip too slowly
- 请求,用于过快删除公共 API
- Ubuntu 更新 pip 太慢
You can solve this issue, by either updating pip via Ubuntu (if there is a newer version) or by installing pip aside from Ubuntu.
您可以通过通过 Ubuntu 更新 pip(如果有更新版本)或安装 pip 来解决这个问题,除了 Ubuntu。
回答by robert_b_clarke
On Ubuntu 14.04 I resolved this by using the pip installation bootstrap script, as described in the documentation
在 Ubuntu 14.04 上,我通过使用 pip 安装引导脚本解决了这个问题,如文档中所述
wget https://bootstrap.pypa.io/get-pip.py
sudo python get-pip.py
That's an OK solution for a development environment.
对于开发环境来说,这是一个不错的解决方案。
回答by Branden Ghena
For fixing pip3 (worked on Ubuntu 14.10):
用于修复 pip3(适用于 Ubuntu 14.10):
easy_install3 -U pip
回答by ggll
Check wether you have an older version of requests
sitting in your ~/.local/lib/python2.7/site-packages/
and remove it if it is the case (change path to reflect your python version). This solved the issue for me.
请检查是否你有一个旧版本的requests
坐在你~/.local/lib/python2.7/site-packages/
并删除它,如果它是(以反映您的Python版本的变化路径)的情况下。这为我解决了这个问题。
回答by PhoebeB
My version of pip on ubuntu suggests:
我在 ubuntu 上的 pip 版本建议:
pip install --upgrade pip
回答by kiok46
This should work for you. Follow these simple steps.
这应该对你有用。按照这些简单的步骤操作。
First, let's remove the pip which is already installed so it won't cause any error.
首先,让我们删除已经安装的 pip,这样它就不会导致任何错误。
Open Terminal.
打开终端。
Type: sudo apt-get remove python-pip
类型:sudo apt-get remove python-pip
It removes pip that is already installed.
它删除已安装的 pip。
Method-1
方法一
Step: 1sudo easy_install -U pip
步骤:1sudo easy_install -U pip
It will install pip latest version.
它将安装 pip 最新版本。
And will return its address: Installed /usr/local/lib/python2.7/dist-packages/pip-6.1.1-py2.7.egg
并且会返回它的地址:Installed /usr/local/lib/python2.7/dist-packages/pip-6.1.1-py2.7.egg
or
或者
Method-2
方法二
Step: 1go to this link.
步骤: 1转到此链接。
Step: 2Right click >> Save as.. with name get-pip.py .
步骤:2右键单击 >> 另存为.. 名称为 get-pip.py 。
Step: 3use: cd to go to the same directory as your get-pip.py file
步骤:3使用:cd 转到与您的 get-pip.py 文件相同的目录
Step: 4use: sudo python get-pip.py
步骤:4使用:sudo python get-pip.py
It will install pip latest version.
它将安装 pip 最新版本。
or
或者
Method-3
方法 3
Step: 1use: sudo apt-get install python-pip
步骤:1使用:sudo apt-get install python-pip
It will install pip latest version.
它将安装 pip 最新版本。
回答by Marius Stanca
Or you can remove all requests
.
或者您可以删除所有requests
.
For example:
例如:
rm -rf /usr/local/lib/python2.7/dist-packages/requests*
rm -rf /usr/local/lib/python2.7/dist-packages/requests*
回答by Bruno O. Sánchez
I tried with every answer avobe, but couldn't make it.
我尝试了所有答案,但无法做到。
Did this and worked
这样做并工作
sudo apt-get purge python-virtualenv
sudo pip install pip -U
After that I just installed virtualenv with pip
之后我只是用 pip 安装了 virtualenv
sudo pip install virtualenv
I built the virtualenv that I was working on and
the package was installed easily.
Get into the virtualenv by using source /bin/activate
and try to install your package, for example:
我构建了我正在处理的 virtualenv,并且安装包很容易。通过使用进入 virtualenvsource /bin/activate
并尝试安装您的包,例如:
pip install terminado
It worked for me, although I was using python2.7 not python3
它对我有用,虽然我使用的是 python2.7 而不是 python3