Python (pip) - RequestsDependencyWarning: urllib3 (1.9.1) or chardet (2.3.0) doesn't match a supported version

115,901

Solution 1

You do have a mixed setup (both apt and pip were used to install system-wide, which is common), and it indeed doesn't match the supported versions of modules required by requests (and pip v1.5.6 is also quite old).

The requests (which version? likely leftover from pip install) requires:
urllib3: 1.21.1 - 1.22
chardet: 3.0.2 - 3.1.0

You have:
urllib3 (1.9.1) from python-urllib3 1.9.1-3 debian package
chardet (2.3.0) from python-chardet 2.3.0-1 debian package

Two options:

  • either downgrade requests to the version from your OS distribution (see what's available with apt show python-requests), or older versions at pypi.org, or

  • or install newer urllib3 and chardet (you can download the wheel files manually from pipy.org and do pip install on them, including any dependencies), either at user level (--user pip install option) or in a virtualenv.

You can test everything in a virtualenv (apt show python-virtualenv). It should even deploy a newer pip for you inside of its virtual envs. It is also possible to install a newer pip 10.0.1 at the user-level (--user) alongside your OS-vendored pip but you need to be careful about that. Good luck!

Solution 2

This is because of different requests module installed by the OS and the python dependencies for your local installation.

It can be solved by upgrading requests:

pip install requests

or

pip3 install requests

Solution 3

Faced similar error when upgraded to urllib3 1.23. Installation of older version 1.22 resolved this error for me.

Did following to install the older urllib3 version:

  1. pip uninstall urllib3
  2. pip install urllib3==1.22

Solution 4

The best practice would be to make sure requests and its dependencies are up to date.

Python 2

$ pip install --upgrade requests

Python 3

$ pip3 install --upgrade requests

Solution 5

I encountered this issue when trying to run docker-compose <some-action> after a system update.

There are a few reasons that can lead to the error mentioned.

I'll add another solution here, maybe it will help somebody if the other solutions doesn't fit his specific scenario.

The following combination solved the problem for me:

pip uninstall urllib3    
pip uninstall chardet
pip install requests 
Share:
115,901
Admin
Author by

Admin

Updated on July 05, 2022

Comments

  • Admin
    Admin almost 2 years

    I found several pages about this issue but none of them solved my problem.

    Even if I do a :

    pip show
    

    I get :

    /usr/local/lib/python2.7/dist-packages/requests/__init__.py:80: RequestsDependencyWarning: urllib3 (1.9.1) or chardet (2.3.0) doesn't match a supported version!
      RequestsDependencyWarning)
    Traceback (most recent call last):
      File "/usr/bin/pip", line 9, in <module>
        load_entry_point('pip==1.5.6', 'console_scripts', 'pip')()
      File "/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 480, in load_entry_point
        return get_distribution(dist).load_entry_point(group, name)
      File "/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 2691, in load_entry_point
        return ep.load()
      File "/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 2322, in load
        return self.resolve()
      File "/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 2328, in resolve
        module = __import__(self.module_name, fromlist=['__name__'], level=0)
      File "/usr/lib/python2.7/dist-packages/pip/__init__.py", line 74, in <module>
        from pip.vcs import git, mercurial, subversion, bazaar  # noqa
      File "/usr/lib/python2.7/dist-packages/pip/vcs/mercurial.py", line 9, in <module>
        from pip.download import path_to_url
      File "/usr/lib/python2.7/dist-packages/pip/download.py", line 22, in <module>
        import requests, six
      File "/usr/local/lib/python2.7/dist-packages/requests/__init__.py", line 90, in <module>
        from urllib3.exceptions import DependencyWarning
    ImportError: cannot import name DependencyWarning
    

    What I did :

    pip install --upgrade chardet
    

    but as explain up, it gaves me the same error.

    so I did :

    sudo apt remove python-chardet
    

    and unistalling all his dependecies. After I reinstall it -> the same :'(

    I did the same for python-pip. After reinstalling it -> the same.
    Here are the lines about urllib3 and chardet versions needed : extract of /usr/local/lib/python2.7/dist-packages/requests/__init__.py :

        # Check urllib3 for compatibility.
        major, minor, patch = urllib3_version  # noqa: F811
        major, minor, patch = int(major), int(minor), int(patch)
        # urllib3 >= 1.21.1, <= 1.22
        assert major == 1
        assert minor >= 21
        assert minor <= 22
    
        # Check chardet for compatibility.
        major, minor, patch = chardet_version.split('.')[:3]
        major, minor, patch = int(major), int(minor), int(patch)
        # chardet >= 3.0.2, < 3.1.0
        assert major == 3
        assert minor < 1
        assert patch >= 2
    
    
    # Check imported dependencies for compatibility.
    try:
        check_compatibility(urllib3.__version__, chardet.__version__)
    except (AssertionError, ValueError):
        warnings.warn("urllib3 ({0}) or chardet ({1}) doesn't match a supported "
                      "version!".format(urllib3.__version__, chardet.__version__),
                      RequestsDependencyWarning)
    

    My versions are :

    ii  python-urllib3 1.9.1-3   all HTTP library with thread-safe connection pooling for Python 
    ii  python-chardet  2.3.0-1  all universal character encoding detector for Python2
    

    I don't have no more ideas...