Python (pip)-RequestsDependencyPolice: urllib3(1.9.1)或 chardet (2.3.0)与支持的版本不匹配

我找到了几页关于这个问题的文章,但没有一页解决了我的问题。

即使我做一个:

pip show

我得到了:

/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

我所做的:

pip install --upgrade chardet

但是解释起来,它给了我同样的错误。

所以我照做了:

sudo apt remove python-chardet

卸载他所有的附属品。 在我重新安装之后-> 相同的:

我做了同样的 python-pip。后重新安装它-> 相同的。
以下是所需的 urllib3chardet版本: /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)

我的版本是:

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

我没有更多的想法..。

161234 次浏览

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!

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

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

I had an older version of requests.

Changing requests version from 2.19.1 to 2.20.1 solved it for me.

At any moment, check the source is the way, specially when the developer has left clear instruction in the comments, like in this case. (Maybe the author should be more specific and put it in the error message, yes)

Open vi /usr/lib/python2.7/site-packages/requests/__init__.py and search for check_compatibility(.

def check_compatibility(urllib3_version, chardet_version):
urllib3_version = urllib3_version.split('.')
assert urllib3_version != ['dev']  # Verify urllib3 isn't installed from git.


# Sometimes, urllib3 only reports its version as 16.1.
if len(urllib3_version) == 2:
urllib3_version.append('0')


# 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.24     <------------------ here
assert major == 1
assert minor >= 21
assert minor <= 24


# 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     <------------------ and here
assert major == 3
assert minor < 1
assert patch >= 2

Then, you know the range of versions of urllib3 and chardet compatible. So, you try with:

pip uninstall urllib3
pip install urllib3==1.24
pip uninstall chardet
pip install chardet==3.0.9 # this will fail, prompting the correct versions available, so you will try to install 3.0.4 instead

It worked for me. Simply execute below commands.

$ sudo pip uninstall requests


$ sudo pip install requests


$ sudo pip uninstall docopt


$ sudo pip install docopt

Here's the reference link for detail!

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

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

Tried to downgrade urllib3 1.25.2 to 1.24.3, but latter was not found.

$ sudo pip install -I urllb3==1.24.3
ERROR: No matching distribution found for urllb3==1.24.3

A quick fix that worked for me: Edit /usr/lib/python3.7/site-packages/requests/__init__.py

In the block:

# 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.24
assert major == 1
assert minor >= 21
assert minor <= 24

Changed the assert minor <= 24 to assert minor <= 25 and this solved my issue - for now.

There's a bug report on Github https://github.com/streamlink/streamlink/issues/2448

Simple you have to update only -

 pip3 install requests

All that's needed is sudo pip install --upgrade requests.

Without sudo you'll get Permission denied, and if you add --user it won't install into system python.

After this, pip list does not get a RequestsDependencyWarning.

The output on my system:

$ sudo pip install --upgrade requests


/usr/lib/python3.7/site-packages/requests/__init__.py:91: RequestsDependencyWarning: urllib3 (1.25.2) or chardet (3.0.4) doesn't match a supported version!
RequestsDependencyWarning)
Collecting requests
Downloading https://files.pythonhosted.org/packages/51/bd/23c926cd341ea6b7dd0b2a00aba99ae0f828be89d72b2190f27c11d4b7fb/requests-2.22.0-py2.py3-none-any.whl (57kB)
|████████████████████████████████| 61kB 510kB/s
Requirement already satisfied, skipping upgrade: idna<2.9,>=2.5 in /usr/lib/python3.7/site-packages (from requests) (2.8)
Requirement already satisfied, skipping upgrade: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /usr/lib/python3.7/site-packages (from requests) (1.25.2)
Collecting certifi>=2017.4.17 (from requests)
Downloading https://files.pythonhosted.org/packages/60/75/f692a584e85b7eaba0e03827b3d51f45f571c2e793dd731e598828d380aa/certifi-2019.3.9-py2.py3-none-any.whl (158kB)
|████████████████████████████████| 163kB 1.1MB/s
Requirement already satisfied, skipping upgrade: chardet<3.1.0,>=3.0.2 in /usr/lib/python3.7/site-packages (from requests) (3.0.4)
Installing collected packages: certifi, requests
Found existing installation: requests 2.21.0
Uninstalling requests-2.21.0:
Successfully uninstalled requests-2.21.0
Successfully installed certifi-2019.3.9 requests-2.22.0

[I would have simply added a small comment on @h3xStream's answer, but don't have enough reputation.]

just update pip: sudo pip install -U pip

I got this error running a virtual python environment (Home Assistant) and the above suggestions didn't work for me since the user (homeassistant) didn't have a password or sudo rights.

The solution in this scenario was to simply deactivate the venv environment and then delete the virtual environment directory and recreate the virtual folder.

To deactivate the python3 venv, simple execute the 'deactivate' bash command anywhere inside your virtual environment tree.

I fixed this problem with

pip install --upgrade requests==2.20.1

If you see version incompatible message like following, you should try other versions. All versions are: here

ERROR: docker-compose 1.24.1 has requirement requests!=2.11.0,!=2.12.2,!=2.18.0,<2.21,>=2.6.1, but you'll have requests 2.21.0 which is incompatible.

I fixed this problem with this command

pip install --upgrade requests==2.20.1

If you see version incompatible message like following, you should try other versions. All versions are: here

ERROR: docker-compose 1.24.1 has requirement requests!=2.11.0,!=2.12.2,!=2.18.0,<2.21,>=2.6.1, but you'll have requests 2.21.0 which is incompatible.

I was facing same issue with below urllib3 and chardet versions.

OS : Ubuntu 18.04

urllib3 : 1.25.6

chardet : 3.0.4

Error : /usr/lib/python3/dist-packages/requests/init.py:80: RequestsDependencyWarning: urllib3 (1.25.6) or chardet (3.0.4) doesn't match a supported version! RequestsDependencyWarning)

solution : update 'requests' pacakge.

$ pip3 install requests

For me the fix was:

pip uninstall urllib3
pip uninstall chardet
pip install requests

Stack:

Centos 7.6.1810

docker-compose 1.24.1 build 4667896 (docker-compose logs give me the warn)

python 2.7.5

pip 8.1.2

In my case there was a problem with the chardet package. I had installed two versions (2.3.0 and 3.04) and for some reason python loaded the old one. My solution was to delete the package manually:

rm -rf /usr/lib/python2.7/site-packages/chardet*

and install it again

pip install chardet

If not already done update also urllib3 and requests to the latest version

pip install --upgrade urllib3
pip install --upgrade requests

Try these two commands, hope you will get success.

sudo python3 -m pip install --upgrade --user urllib3==1.24.3


sudo apt-get update

I was facing the same issue.

pip install --upgrade requests

I ran this command and the issue is fixed.