我使用pip的时候“没有名为zlib的模块”错误

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了我使用pip的时候“没有名为zlib的模块”错误相关的知识,希望对你有一定的参考价值。

我在mac上使用终端,无论何时我尝试使用pip,我都会收到以下错误消息,告诉我它找不到名为zlib的模块:


$ pip --version

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/pip/_vendor/requests/packages/__init__.py", line 27, in <module>
    from . import urllib3
  File "/usr/local/lib/python3.6/site-packages/pip/_vendor/requests/packages/urllib3/__init__.py", line 8, in <module>
    from .connectionpool import (
  File "/usr/local/lib/python3.6/site-packages/pip/_vendor/requests/packages/urllib3/connectionpool.py", line 42, in <module>
    from .response import HTTPResponse
  File "/usr/local/lib/python3.6/site-packages/pip/_vendor/requests/packages/urllib3/response.py", line 3, in <module>
    import zlib
ModuleNotFoundError: No module named 'zlib'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.5/bin/pip", line 7, in <module>
    from pip import main
  File "/usr/local/lib/python3.6/site-packages/pip/__init__.py", line 21, in <module>
    from pip._vendor.requests.packages.urllib3.exceptions import DependencyWarning
  File "/usr/local/lib/python3.6/site-packages/pip/_vendor/requests/__init__.py", line 62, in <module>
    from .packages.urllib3.exceptions import DependencyWarning
  File "/usr/local/lib/python3.6/site-packages/pip/_vendor/requests/packages/__init__.py", line 29, in <module>
    import urllib3
  File "/usr/local/lib/python3.6/site-packages/urllib3/__init__.py", line 8, in <module>
    from .connectionpool import (
  File "/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 36, in <module>
    from .response import HTTPResponse
  File "/usr/local/lib/python3.6/site-packages/urllib3/response.py", line 3, in <module>
    import zlib

ModuleNotFoundError: No module named 'zlib'

我已经阅读了几条带有相同错误消息的SO帖子,并尝试了他们的解决方案,包括尝试使用自制软件安装zlib,失败,并更新我的Xcode开发人员工具。我之前使用python get-pip.py安装了pip,它说安装成功了。

我需要pip的原因是安装一个在python 2.7上使用的包,但是执行$ pip install "package-name"会产生与上面相同的错误。如果有帮助,我在我的机器上安装了Python 2和3。我对pip和使用命令行有点新意,我非常困惑;如果有人能帮助我,我真的很感激。

答案

这是OP。我能够解决这个问题,并想在这里发布我的解决方案以防万一。

基本上我认为它发生是因为Python2在我的机器上是默认的,但是pip默认指向与Python3有关的资源,或类似的东西。做pip2 --version反而提供了预期的响应。

以上是关于我使用pip的时候“没有名为zlib的模块”错误的主要内容,如果未能解决你的问题,请参考以下文章

错误处理: pip install 时候 “Read timed out”

pip安装python包出错:Could not find a version that satisfies the requirement skimage (from versions: )(示例代

我的Android进阶之旅OKHttp出现错误 java.lang.IllegalStateException: Expected Android API level 21+ but was 19(代

使用pip安装包提示TLS证书错误解决办法

用pip安装python第三方包的时候显示错误

pip3安装Pillow错误的问题