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:24

Or you can remove all requests.

For example:

  • rm -rf /usr/local/lib/python2.7/dist-packages/requests*
查看更多
虎瘦雄心在
3楼-- · 2020-01-24 19:24

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.

Open Terminal.

Type: sudo apt-get remove python-pip

It removes pip that is already installed.

Method-1

Step: 1 sudo easy_install -U pip

It will install pip latest version.

And will return its address: Installed /usr/local/lib/python2.7/dist-packages/pip-6.1.1-py2.7.egg

or

Method-2

Step: 1 go to this link.

Step: 2 Right click >> Save as.. with name get-pip.py .

Step: 3 use: cd to go to the same directory as your get-pip.py file

Step: 4 use: sudo python get-pip.py

It will install pip latest version.

or

Method-3

Step: 1 use: sudo apt-get install python-pip

It will install pip latest version.

查看更多
不美不萌又怎样
4楼-- · 2020-01-24 19:28

While this previous answer might be the reason, this snipped worked for me as a solution (in 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)

查看更多
男人必须洒脱
5楼-- · 2020-01-24 19:28

I tried with every answer below, 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

sudo pip install virtualenv

I builded 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:

pip install terminado

It worked for me, although I was using python2.7 not python3

查看更多
淡お忘
6楼-- · 2020-01-24 19:28

Check if have a python interpreter alive in any of the terminal windows. If so kill it and try sudo pip which worked for me.

查看更多
时光不老,我们不散
7楼-- · 2020-01-24 19:32

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.

查看更多
登录 后发表回答