Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImportError: cannot import name DependencyWarning

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?

like image 503
MaYHEM Avatar asked Jul 05 '17 13:07

MaYHEM


4 Answers

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

sudo pip install --upgrade requests
like image 104
luator Avatar answered Oct 04 '22 10:10

luator


There are two cases that occur this problem.

  1. There is duplicated PATH of pip.

    apt-get remove python-pip

    easy_install pip

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

    You can solve this issue by updating pip.

like image 41
heltdog Avatar answered Oct 04 '22 12:10

heltdog


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.

like image 27
Andrew Chong Avatar answered Oct 04 '22 12:10

Andrew Chong


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
like image 28
Megamozg Avatar answered Oct 04 '22 11:10

Megamozg