RequestsDependencyWarning:urllib3(1.9.1)或chardet(2.3.0)与支持的版本

时间:2018-05-06 16:54:15

标签: python pip python-requests urllib3 chardet

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

即使我做了:

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

并解除他所有的依赖。 我重新安装后 - &gt;同样的:'(

我为python-pip做了同样的事情。重新安装后 - &gt;同样的。

以下是有关所需的urllib3和chardet版本的行: /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

我没有更多的想法......

感谢大家,对不起我的英语:)

20 个答案:

答案 0 :(得分:33)

这是因为操作系统安装了不同的请求模块以及本地安装的python依赖项。

可以通过升级请求来解决:

pip install requests

pip3 install requests

答案 1 :(得分:5)

您确实有混合设置(aptpip都用于安装系统范围,这很常见),它确实与所需的模块支持版本不匹配请求(和pip v1.5.6也很旧)。

requests(哪个版本?可能来自pip install)可能需要:
urllib3:1.21.1 - 1.22
chardet:3.0.2 - 3.1.0

你有:
来自python-urllib3的urllib3(1.9.1)1.9.1-3 debian包
chardet(2.3.0)来自python-chardet 2.3.0-1 debian package

两个选项:

  • 要么将requests降级到您的操作系统发行版中的版本(请参阅apt show python-requests提供的内容),要么将旧版本降级到pypi.org,或

    < / LI>
  • 或安装更新的urllib3和chardet(您可以从用户级别(pip install pip手动从pipy.org手动下载轮文件并对其进行--user,包括任何依赖项)安装选项)或在virtualenv。

您可以在virtualenvapt show python-virtualenv)中测试所有内容。它甚至应该在其虚拟环境中为你部署一个更新的点。同样possible在用户级别(--user)旁边安装一个较新的pip 10.0.1以及你的OS销售点,但你需要careful。祝你好运!

答案 2 :(得分:5)

对我有用。只需执行以下命令即可。

$ sudo pip uninstall requests

$ sudo pip install requests

$ sudo pip uninstall docopt

$ sudo pip install docopt

这里是参考文献link for detail

答案 3 :(得分:4)

最佳做法是确保请求及其依赖项是最新的。

Python 2

  

$ pip install-升级请求

Python 3

  

$ pip3 install-升级请求

答案 4 :(得分:2)

升级到urllib3 1.23时遇到类似的错误。安装旧版本1.22为我解决了此错误。

要执行以下操作来安装旧版urllib3

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

答案 5 :(得分:1)

我通过使用 pip 手动更新请求包解决了这个问题:

pip install --upgrade requests

答案 6 :(得分:1)

只需要sudo pip install --upgrade requests

没有sudo,您将得到Permission denied, 并且如果您添加--user,它将不会安装到系统python中。

此后,pip list没有收到RequestsDependencyWarning。

我系统上的输出:

$ 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

[我只想对@ h3xStream的答案添加一点评论, 但信誉不足。]

答案 7 :(得分:1)

在系统更新后尝试运行docker-compose <some-action>时遇到此问题。

有一些原因可能导致上述错误。

我将在此处添加另一个解决方案,如果其他解决方案不适合他的特定情况,那么它可能会对某人有所帮助。

以下组合为我解决了这个问题:

pip uninstall urllib3    
pip uninstall chardet
pip install requests 

答案 8 :(得分:1)

在任何时候,都要检查源代码,特别是在开发人员在注释中留下清晰说明的情况下,例如在这种情况下。 (也许作者应该更具体一些,并把它放在错误消息中,是的)

打开const Header = () => { const firstName = "Ashraf"; const lastName = "Fathi"; const date = new Date(); const hours = date.getHours(); let timeOfDay; const styles = { color: "" } if (hours < 12) { timeOfDay = "Good morning" styles.color = "#ff474d" } else if (hours >= 12 && hours < 17) { timeOfDay = "Good afternoon" styles.color = "#7b5dff" } else { timeOfDay = "Good night" styles.color = "#01ff41" } return( <div> <h1 className="navbar" style={styles}>{timeOfDay} {`${firstName} ${lastName}`} It is currently {hours} clock</h1> </div> ) } 并搜索vi /usr/lib/python2.7/site-packages/requests/__init__.py

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 urllib3的版本范围。因此,您尝试:

chardet

答案 9 :(得分:1)

我有一个较旧的requests版本。

requests版本从2.19.1更改为2.20.1对我来说解决了这个问题。

答案 10 :(得分:0)

试图将urllib3 1.25.2降级到1.24.3,但未找到后者。

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

对我有用的快速修复: 编辑/usr/lib/python3.7/site-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.24     
assert major == 1
assert minor >= 21
assert minor <= 24

assert minor <= 24更改为assert minor <= 25,现在就解决了我的问题。

有关Github https://github.com/streamlink/streamlink/issues/2448的错误报告

答案 11 :(得分:0)

简单,您只需更新-

 pip3 install requests

答案 12 :(得分:0)

只需更新pip:sudo pip install -U pip

答案 13 :(得分:0)

我在运行虚拟python环境(家庭助理)时遇到此错误,并且由于用户(家庭助手)没有密码或sudo权限,上述建议对我不起作用。

这种情况下的解决方案是简单地停用venv环境,然后删除虚拟环境目录并重新创建虚拟文件夹。

要停用python3 venv,只需在虚拟环境树内的任何位置执行'deactivate'bash命令即可。

答案 14 :(得分:0)

我通过

解决了这个问题
pip install --upgrade requests==2.20.1

如果看到如下所示的版本不兼容消息,则应尝试其他版本。所有版本均为: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.

答案 15 :(得分:0)

我使用此命令解决了这个问题

pip install --upgrade requests==2.20.1

如果看到如下所示的版本不兼容消息,则应尝试其他版本。所有版本均为: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.

答案 16 :(得分:0)

我在以下urllib3和chardet版本中遇到相同的问题。

操作系统:Ubuntu 18.04

urllib3:1.25.6

chardet:3.0.4

错误:/usr/lib/python3/dist-packages/requests/init.py:80:RequestsDependencyWarning:urllib3(1.25.6)或chardet(3.0.4)不匹配支持的版本!   RequestsDependencyWarning)

解决方案:更新“请求”功能。

$ pip3安装请求

答案 17 :(得分:0)

对我来说,解决方法是:

pip uninstall urllib3    
pip uninstall chardet
pip install requests

堆栈:

Centos 7.6.1810

docker-compose 1.24.1 build 4667896(docker-compose日志给我警告)

python 2.7.5

点8.1.2

答案 18 :(得分:0)

就我而言,chardet软件包有问题。我已经安装了两个版本(2.3.0和3.04),并且由于某种原因python加载了旧版本。我的解决方案是手动删除该程序包:

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

然后重新安装

pip install chardet

如果尚未完成更新,请同时更新urllib3并请求最新版本

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

答案 19 :(得分:0)

尝试这两个命令,希望您能成功。

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

sudo apt-get update