ImportError: cannot import name DependencyWarning

Viewed 14655

I am using python 2.7.12. When i do import requests, I see the error below.

Tried uninstalling & installing requests, upgrading pip as well, but no luck, still same issue.

Python 2.7.12 (default, Nov 19 2016, 06:48:10)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
/home/test/.local/lib/python2.7/site-packages/requests/__init__.py:80: 
RequestsDependencyWarning: urllib3 (1.13.1) or chardet (2.3.0) doesn't match a supported version!
RequestsDependencyWarning)

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/test/.local/lib/python2.7/site-packages/requests/__init__.py", line 90, in <module>
from urllib3.exceptions import DependencyWarning
ImportError: cannot import name DependencyWarning

How can I solve this?

8 Answers

I had the same error and was able to fix it by upgrading requests with the following command:

sudo pip install --upgrade requests

In my case, I changed the code like following

  • Open up file: /usr/lib/python2.7/site-packages/pip/__init__.py and find this line.

    from pip._vendor.requests.packages.urllib3.exceptions import DependencyWarning

  • Check if pip._vendor.request folders are there. If yes, then it must be python path issue. If no, do following.
  • Remove text before urllib3 and change like this.

    from urllib3.exceptions import DependencyWarning

I will also try to make PR request about this.

If sudo pip install --upgrade requests didn't worked (as in my case) try to uninstall and install requests with no-cache option:

sudo pip --no-cache-dir uninstall requests
sudo pip --no-cache-dir install requests

Just do these steps:

$ sudo pip uninstall requests
$ sudo pip install requests
$ sudo pip uninstall docopt
$ sudo pip install docopt

or

pip install --upgrade --force-reinstall requests

I managed to fix this issue just by upgrading urllib3:

sudo pip install --upgrade urllib3

None of the above answers work for me (cause whenever I do pip xxx, I got the same exception: cannot import name DependencyWarning), finally I managed to fix Pip by doing this:

easy_install pip

As easy as that ...

Related