pip Can‘t connect to HTTPS URL because the SSL module is not available.

问题描述

环境:

  • Python 3.10.5
  • pip 22.1.2

在尝试pip install request-html时候爆出如下错误:

Could not fetch URL https://pypi.org/simple/pyecharts/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/pyecharts/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.")) - skipping
ERROR: Could not find a version that satisfies the requirement pyecharts (from versions: none)
ERROR: No matching distribution found for pyecharts

解决办法

看报错信息究其本质应该是在运行的时候缺少ssl模块

所以先尝试了关闭SSL认证并添加trusted host(如下是pip.conf的配置,关于pip.conf如何配置请参考):

[global]
index-url=https://pypi.tuna.tsinghua.edu.cn/simple/
extra-index-url=
        http://mirrors.aliyun.com/pypi/simple/
        http://pypi.douban.com/simple
        http://pypi.mirrors.ustc.edu.cn/simple/

[install]
trusted-host=
        pypi.tuna.tsinghua.edu.cn
        mirrors.aliyun.com
        pypi.douban.com
        pypi.mirrors.ustc.edu.cn
        download.openmmlab.com

proxy_servers:
  http: http://xxx.xxx.x.xx:8080
  https: https://xxx.xxx.x.xx:8080
ssl_verify: false

或者使用自定义(非默认路径)pip.conf

export PIP_CONFIG_FILE=/path/to/pip.conf

但是这个办法毕竟只是绕过去,但是依旧使得很多需要ssl模块的库不能运行,毕竟缺少这个库,就比如我要安装的requests-html。

要解决这个问题就需要重新编译(安装)python,并重新配置好对应的openssl版本 [1][2][3]。

[1]https://stackoverflow.com/questions/5937337/building-python-with-ssl-support-in-non-standard-location
[2]https://peps.python.org/pep-0644/
[3]https://techglimpse.com/install-python-openssl-support-tutorial/

你可能感兴趣的:(问题札记,python,ssl)