解决Python3.10报错问题 SSLError(“Can‘t connect to HTTPS URL because the SSL module is not available

在Linux上执行python脚本,访问SSH远程服务时,报错:没有 paramiko。于是执行:

pip3 install paramiko 

报错:ModuleNotFoundError: No module named '_cffi_backend'

pip3 install --upgrade cffi

报错如下:
WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Looking in indexes: https://pypi.doubanio.com/simple
Requirement already satisfied: cffi in ./site-packages (1.16.0)
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/cffi/
Requirement already satisfied: pycparser in ./site-packages (from cffi) (2.21)
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
Could not fetch URL https://pypi.doubanio.com/simple/pip/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.doubanio.com', port=443): Max retries exceeded with url: /simple/pip/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.")) - skipping
WARNING: There was an error checking the latest version of pip.

You have mail in /var/spool/mail/root

解决方案:
首先:先切换镜像源,没有解决

pip3 install  https://pypi.tuna.tsinghua.edu.cn/simple cffi

pip3 install https://pypi.tuna.tsinghua.edu.cn/simple pyOpenSSL

pip install pymysql -i http://pypi.tuna.tsinghua.edu.cn/simple/ --trusted-host pypi.tuna.tsinghua.edu.cn

其次:没有解决,继续找根因,原来:python3.10 缺少 openssl 

解决这个问题,找到了以下博客[引用过来],供大家参考【精选】Caused by SSLError(“Can‘t connect to HTTPS URL because the SSL module is not available.“) 详解_tobybo的博客-CSDN博客

第一步:安装 openssl-1.1.1

  • wget https://www.openssl.org/source/openssl-1.1.1n.tar.gz --no-check-certificate 下载openssl1.1.1
  • tar -zxf openssl-1.1.1n.tar.gz 解压
  • cd openssl-1.1.1n
  • ./config --prefix=/usr/local/openssl 设置安装目录 可以自定义 但是要记住,后面会用到--做了修改,把./Configure改为 ./config
  • make -j && make install 编译并安装

第二步:重新编译 python3.10

  • 切换到 python3.10 解压包目录 /usr/local/python3/Python-3.10.9
  • 已经编译过的可以先 make clean 清理一下
  • ./configure --prefix=/usr/local/python3 --with-openssl=/usr/local/openssl --with-openssl-rpath=auto  
  • make -j && make install

按照这两个步骤,问题解决。剩余详细的逻辑见博客。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值