如何修复“ ImportError:无法导入名称IncompleteRead”?

本文翻译自:How do I fix 'ImportError: cannot import name IncompleteRead'?

When I try to install anything with pip or pip3 , I get: 当我尝试使用pippip3安装任何东西时,我得到:

$ 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? 我该如何解决这个问题?


#1楼

参考:https://stackoom.com/question/1QIEU/如何修复-ImportError-无法导入名称IncompleteRead


#2楼

The problem is the Python module requests . 问题是Python模块的requests It can be fixed by 可以通过固定

$ 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


#3楼

This problem is caused by a mismatch between your pip installation and your requests installation. 此问题是由您的pip安装与请求安装之间的不匹配引起的。

As of requests version 2.4.0 requests.compat.IncompleteRead has been removed . 从请求版本2.4.0 开始,已经删除了 requests.compat.IncompleteRead Older versions of pip, eg from July 2014 , still relied on IncompleteRead . 较早版本的pip,例如从2014年7月开始 ,仍然依赖IncompleteRead In the current version of pip, the import of IncompleteRead has been removed. 当前版本的pip中,已删除了IncompleteRead的导入。

So the one to blame is either: 因此,应该怪的是:

  • requests, for removing public API too quickly 请求,以太快地删除公共API
  • Ubuntu for updating pip too slowly Ubuntu的更新点太慢

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(如果有较新版本)或通过在Ubuntu之外安装pip来解决此问题。


#4楼

While this previous answer might 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)


#5楼

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. 对于开发环境来说,这是一个好的解决方案。


#6楼

要修复pip3(在Ubuntu 14.10上工作):

easy_install3 -U pip
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值