ImportError:没有名为“ requests.packages.urllib3”的模块

时间:2018-09-06 17:07:30

标签: python urllib3

我正在测试一个应用程序,并且出现上述错误“ ImportError:没有名为'requests.packages.urllib3'的模块”。下面是详细信息。

[root@lab ~]# python /opt/test/panda_API.py
Traceback (most recent call last):
  File "/opt/test/panda_API.py", line 8, in <module>
    import requests
  File "/usr/lib/python2.6/site-packages/requests/__init__.py", line 58, in <module>
    from . import utils
  File "/usr/lib/python2.6/site-packages/requests/utils.py", line 32, in <module>
    from .exceptions import InvalidURL
  File "/usr/lib/python2.6/site-packages/requests/exceptions.py", line 10, in <module>
    from .packages.urllib3.exceptions import HTTPError as BaseHTTPError
  File "/usr/lib/python2.6/site-packages/requests/packages/__init__.py", line 99, in load_module
    raise ImportError("No module named '%s'" % (name,))
ImportError: No module named 'requests.packages.urllib3'

为了解决这个问题,我尝试pip install requests。然后会弹出以下错误。

[root@lab ~]# pip install requests
Traceback (most recent call last):
  File "/usr/bin/pip", line 5, in <module>
    from pkg_resources import load_entry_point
  File "/usr/lib/python2.6/site-packages/pkg_resources/__init__.py", line 954, in <module>
    class Environment:
  File "/usr/lib/python2.6/site-packages/pkg_resources/__init__.py", line 958, in Environment
    self, search_path=None, platform=get_supported_platform(),
  File "/usr/lib/python2.6/site-packages/pkg_resources/__init__.py", line 188, in get_supported_platform
    plat = get_build_platform()
  File "/usr/lib/python2.6/site-packages/pkg_resources/__init__.py", line 388, in get_build_platform
    from sysconfig import get_platform
ImportError: No module named sysconfig

我已在此处搜索有关堆栈溢出和其他平台的解决方案,最接近此堆栈溢出页面的解决方案。 (ImportError: No module named sysconfig--can't get pip working)。

我已经尝试了上面链接中建议的步骤,但是相同的错误“ ImportError:没有名为sysconfig的模块”不断重复。

运行“ pip -V”,生成相同的错误。 运行推荐的命令以检查setuptools的版本,生成以下错误--------

    [root@lab pkg_resources]# python2.6 -c "import setuptools; print(setuptools.__version__)"
`Traceback (most recent call last):
    File "<string>", line 1, in <module>
    File "/usr/lib/python2.6/site-packages/setuptools/__init__.py", line 14, in <module     >
      import setuptools.version
    File "/usr/lib/python2.6/site-packages/setuptools/version.py", line 1, in <module>
      import pkg_resources
    File "/usr/lib/python2.6/site-packages/pkg_resources/__init__.py", line 954, in <mo     dule>
      class Environment:
    File "/usr/lib/python2.6/site-packages/pkg_resources/__init__.py", line 958, in Env     ironment
      self, search_path=None, platform=get_supported_platform(),
    File "/usr/lib/python2.6/site-packages/pkg_resources/__init__.py", line 188, in get     _supported_platform
      plat = get_build_platform()
    File "/usr/lib/python2.6/site-packages/pkg_resources/__init__.py", line 388, in get     _build_platform
      from sysconfig import get_platform
  ImportError: No module named sysconfig

我已经检查了/usr/lib/python2.6/site-packages,但没有pkg_resources.py。相反,我拥有的是目录pkg_resources

看来我有一个更复杂的案子。拜托,我需要帮助!

注意:

操作系统:CentOS release 6.10 (Final)和Python版本:Python 2.6.6

2 个答案:

答案 0 :(得分:0)

首先运行此命令,

pip install requests urllib3 pyOpenSSL --force --upgrade

然后安装pyOpenSSL版本16.2.0并运行此命令

pip install pyOpenSSL==16.2.0

答案 1 :(得分:0)

更新您的分发包! Python 2.6已死。