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

Python(pip)-RequestsDependencyWarning:urllib3(1.9.1)或chardet(2.3.0)不';与支持的版本不匹配,python,pip,python-requests,urllib3,chardet,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) Traceb

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

即使我做了一件事:

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
但正如我解释的那样,它也给了我同样的错误

所以我做了:

sudo apt remove python-chardet
还不算他所有的家属。 重新安装后->相同:'(

我对python-pip做了同样的操作。重新安装后->同样的操作。
以下是有关
urlib3
chardet
所需版本的行:
/usr/local/lib/python2.7/dist包/请求/\uuu init\uuuu.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)
我没有更多的想法

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

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

请求
(哪个版本?可能是从
pip安装
中遗留下来的)需要:
urllib3:1.21.1-1.22
chardet:3.0.2-3.1.0

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

两种选择:

  • requests
    降级到操作系统发行版的版本(请参阅
    apt show python requests
    )或pypi.org上的旧版本,或

  • 或者在用户级别(
    --user
    pip安装选项)或虚拟环境中安装更新的urllib3和chardet(您可以从pipy.org手动下载车轮文件,并在其上执行
    pip安装
    ,包括任何依赖项)


您可以在(
apt show python virtualenv
)中测试所有内容。它甚至应该在虚拟环境中为您部署一个更新的pip。在用户级别(
--user
)安装一个新的PIP10.0.1,与您的操作系统供应商的pip一起使用,但您需要对此有所了解。祝你好运

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

安装较旧的
urllib3
版本时执行了以下操作:

  • pip卸载urllib3
  • pip安装urllib3==1.22

  • 这是因为操作系统安装的请求模块不同,本地安装的python依赖项也不同

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

    pip install requests
    


    我有一个较旧版本的
    请求


    请求
    版本从
    2.19.1
    更改为
    2.20.1
    为我解决了这个问题。

    随时检查源代码是否正确,特别是当开发人员在注释中留下了清晰的说明时,就像在这种情况下一样。(可能作者应该更具体一些,并将其放在错误消息中,是的)

    打开
    vi/usr/lib/python2.7/site packages/requests/\uuuu init\uuuuu.py
    并搜索
    检查兼容性(


    它对我有效。只需执行以下命令

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

    这是参考资料!

    我在系统更新后尝试运行
    docker compose
    时遇到了这个问题

    有几个原因可能导致上述错误

    我将在这里添加另一个解决方案,如果其他解决方案不适合某个人的特定场景,可能会有所帮助

    以下组合解决了我的问题:

    pip uninstall urllib3    
    pip uninstall chardet
    pip install requests 
    

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

    Python 2

    $pip安装--升级请求

    Python 3

    $pip3安装--升级请求


    试图将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/\uuuuu init\uuuuuuuuu.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
    
    #检查urllib3的兼容性。
    大调,小调,patch=urllib3#u版本#noqa:F811
    大调,小调,补丁=int(大调),int(小调),int(补丁)
    #urllib3>=1.21.1,=21
    
    assert minor简单您只需更新-

     pip3 install requests
    

    只需要
    sudopip安装——升级请求

    如果没有sudo,您将获得被拒绝的
    权限
    , 如果您添加
    --user
    ,它将不会安装到系统python中

    在此之后,
    pip list
    不会收到requestsdependency警告

    我的系统上的输出:

    $ 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
    
    $sudo pip安装--升级请求
    /usr/lib/python3.7/site packages/requests/__init____;py.py:91:RequestsDependencyWarning:urllib3(1.25.2)或chardet(3.0.4)与支持的版本不匹配!
    请求依赖(警告)
    收集请求
    正在下载https://files.pythonhosted.org/packages/51/bd/23c926cd341ea6b7dd0b2a00aba99ae0f828be89d72b2190f27c11d4b7fb/requests-2.22.0-py2.py3-none-any.whl (57kB)
    |████████████████████████████████| 61kB 510kB/s
    已满足要求,跳过升级:idna=2.5 in/usr/lib/python3.7/site-packages(来自请求)(2.8)
    已满足要求,正在跳过升级:urllib3=1.25.0,!=1.25.1,=1.21.1 in/usr/lib/python3.7/site-packages(来自请求)(1.25.2)
    收集证书i>=2017.4.17(来自请求)
    正在下载https://files.pythonhosted.org/packages/60/75/f692a584e85b7eaba0e03827b3d51f45f571c2e793dd731e598828d380aa/certifi-2019.3.9-py2.py3-none-any.whl (158kB)
    |████████████████████████████████| 163kB 1.1MB/s
    已满足要求,跳过升级:chardet=3.0.2 in/usr/lib/python3.7/site-packages(来自请求)(3.0.4)
    安装收集的软件包:certifi,请求
    找到现有安装:requests 2.21.0
    卸载请求-2.21.0:
    已成功卸载请求-2.21.0
    成功安装
    
    pip uninstall urllib3    
    pip uninstall chardet
    pip install requests 
    
    $ sudo pip install -I urllb3==1.24.3
    ERROR: No matching distribution found for urllb3==1.24.3
    
    # 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
    
     pip3 install requests
    
    $ 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
    
    pip install --upgrade requests==2.20.1
    
    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.
    
    pip install --upgrade requests==2.20.1
    
    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.
    
    pip uninstall urllib3    
    pip uninstall chardet
    pip install requests
    
    rm -rf /usr/lib/python2.7/site-packages/chardet*
    
    pip install chardet
    
    pip install --upgrade urllib3
    pip install --upgrade requests
    
    sudo python3 -m pip install --upgrade --user urllib3==1.24.3
    
    sudo apt-get update