How do I fix 'ImportError: cannot import name

2020-01-24 18:41发布

When I try to install anything with pip or pip3, I get:

$ 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.

How can I fix this problem?

标签: python pip
16条回答
看我几分像从前
2楼-- · 2020-01-24 19:33

The problem is the Python module 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.

查看更多
forever°为你锁心
3楼-- · 2020-01-24 19:34

On Ubuntu 14.04 I resolved this by using the pip installation bootstrap script, as described in the documentation

wget https://bootstrap.pypa.io/get-pip.py
sudo python get-pip.py

That's an OK solution for a development environment.

查看更多
我只想做你的唯一
4楼-- · 2020-01-24 19:34

Simply running easy_install -U pip resolved my problem.

查看更多
做个烂人
5楼-- · 2020-01-24 19:35
  1. sudo apt-get remove python-pip
  2. sudo easy_install requests==2.3.0
  3. sudo apt-get install python-pip
查看更多
来,给爷笑一个
6楼-- · 2020-01-24 19:37

This problem is caused by a mismatch between your pip installation and your requests installation.

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 version of pip, the import of IncompleteRead has been removed.

So the one to blame is either:

  • requests, for removing public API too quickly
  • Ubuntu for updating pip too slowly

You can solve this issue, by either updating pip via Ubuntu (if there is a newer version) or by installing pip aside from Ubuntu.

查看更多
手持菜刀,她持情操
7楼-- · 2020-01-24 19:38

You can download recent packages manually from these pages:

Then, install it by running dpkg:

dpkg -i *.deb
查看更多
登录 后发表回答