[一篇就够]pip install 下载模块时提示“Can‘t connect to HTTPS URL because the SSL module is not available.“

环境

centos 7

python 安装版本 3.8.3

起因

python安装完成后,需要import requests模块。使用pip install requests 提示


WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
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/pip/
WARNING: Retrying (Retry(total=3, 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/pip/
WARNING: Retrying (Retry(total=2, 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/pip/
WARNING: Retrying (Retry(total=1, 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/pip/

检查

1 检查openssl 是否存在:openssl version ——》检查后确认存在,版本1:1.0.1e-60.el7

尝试

1 检查编译方式:指定openssl路径

参照网上方法

./configure --prefix=/usr/local/python3 --with-openssl=/usr/local/openssl
make
make install

安装后,仍然存在ssl问题。

2 尝试安装离线requests包——》此方法略复杂,建议直接跳过,本人也未尝试成功

3 重新openssl版本,并按1的方法再次编译——》无效

(该方法每次建议把之前创建的python安装路径里的文件清空后再尝试)

  • 安装openssl方法
1 下载

https://www.openssl.org/source/openssl-1.1.1-pre8.tar.gz

2 编译安装

./config --prefix=/usr/local/openssl no-zlib #不需要zlib
make
make install

3 备份原配置

mv /usr/bin/openssl /usr/bin/openssl.bak
mv /usr/include/openssl/ /usr/include/openssl.bak

4 更新新配置

ln -s /usr/local/openssl/include/openssl /usr/include/openssl

ln -s /usr/local/openssl/lib/libssl.so.1.1 /usr/local/lib64/libssl.so

5 将安装好的openssl命令软连到/usr/bin/openssl
ln -s /usr/local/openssl/bin/openssl /usr/bin/openssl

6 系统生效

#写入openssl库文件的搜索路径
echo "/usr/local/openssl/lib" >> /etc/ld.so.conf

#使修改后的/etc/ld.so.conf生效 
ldconfig -v

7 查看版本

openssl version
OpenSSL 1.1.1-pre8 (beta) 20 Jun 2018

4 尝试更换成国内镜像源——》成功

(1)阿里云 http://mirrors.aliyun.com/pypi/simple/
(2)豆瓣http://pypi.douban.com/simple/
(3)清华大学 https://pypi.tuna.tsinghua.edu.cn/simple/
(4)中国科学技术大学 http://pypi.mirrors.ustc.edu.cn/simple/
(5)华中科技大学http://pypi.hustunique.com/

pip install -i http://mirrors.aliyun.com/pypi/simple/ requests --trusted-host mirrors.aliyun.com

- 注意!

这里必须加上–trusted-host mirrors.aliyun.com,否则仍然报错。

如果不想每次都加,就修改python的配置文件吧:

[install]
trusted-host = pypi.douban.com
结论

1,推荐直接使用方法4

2,如果单独尝试4方法无效,建议尝试3-1-4组合方法试试

传送门

python 3.8安装方法

python更新镜像源

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

聊聊技术

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值