python3.10及以上版本编译安装ssl模块的详细过程
作者:伏逸 时间:2022-05-05 07:26:28
前言
由于python3.10之后版本不在支持libressl使用ssl,需要使用openssl安装来解决编译安装python时候遇到的ssl模块导入失败的问题,这里需要用的openssl1.1.1版本或者更高版本
编译安装openssl
下载地址
参见https://www.openssl.org/,包括以下版本:
https://www.openssl.org/source/openssl-3.1.0-alpha1.tar.gz
https://www.openssl.org/source/openssl-1.1.1s.tar.gz
https://www.openssl.org/source/openssl-3.0.7.tar.gz
编译安装
注:编译之前请先确保系统中安装了make以及gcc的软件包。,编译安装前确认/usr/include/openssl//为空
tar -zxf openssl-1.1.1s.tar.gz
cd openssl-1.1.1s/
./config -fPIC --prefix=/usr/include/openssl enable-shared
make
make install
其中:
l -fPIC: 位置无关代码
l --prefix=: 路径 一般选 /usr/include/openssl
l enbale-shared: 动态库
安装openssl3.0.7问题
安装openssl3.0.7时候报错,查看对应文件显示模块缺少,需要加载导入模块
报错原因: 缺少IPC/Cmd.pm模块
解决方法:
安装perl-CPAN
$ yum install -y perl-CPAN
进入CPAN的she模式,首次进入需要配置shel,按照提示操作即可
$ perl -MCPAN -e shell
在shell中安装缺少的模块,确定是cpan[1]算是进入了操作命令入口
cpan[1]> install IPC/Cmd.pm
退出界面回到shell
cpan[1]> quit
安装成功后,重新编译OpenSSL即可
编译安装python3.11.2
下载地址
python下载地址
https://www.python.org/ftp/python/3.11.2/Python-3.11.2.tgz
编译安装
需要修改解压后的python Moudle/Setup文件
tar -xf Python-3.11.2.tar.xzcd Python-3.11.2/
需要修改解压后的python Moudle/Setup文件
# To statically link OpenSSL:
- # _ssl _ssl.c $(OPENSSL_INCLUDES) $(OPENSSL_LDFLAGS) \
+ _ssl _ssl.c $(OPENSSL_INCLUDES) $(OPENSSL_LDFLAGS) \
- # -l:libssl.a -Wl,--exclude-libs,libssl.a \
+ -l:libssl.a -Wl,--exclude-libs,libssl.a \
- # -l:libcrypto.a -Wl,--exclude-libs,libcrypto.a
+ -l:libcrypto.a -Wl,--exclude-libs,libcrypto.a
- # _hashlib _hashopenssl.c $(OPENSSL_INCLUDES) $(OPENSSL_LDFLAGS) \
+ _hashlib _hashopenssl.c $(OPENSSL_INCLUDES) $(OPENSSL_LDFLAGS) \
- # -l:libcrypto.a -Wl,--exclude-libs,libcrypto.a
+ -l:libcrypto.a -Wl,--exclude-libs,libcrypto.a
编译安装,注意configure命令
此处参考了:configure配置
chmod +x configure
mkdir /usr/local/python-3.11.2
./configure --prefix=/usr/local/python-3.11.2 --with-zlib=/usr/include/ --with-openssl-rpath=auto --with-openssl=/usr/include/openssl OPENSSL_LDFLAGS=-L/usr/include/openssl OPENSSL_LIBS=-l/usr/include/openssl/ssl OPENSSL_INCLUDES=-I/usr/include/openssl
make -j 4
make install
验证是否成功安装ssl模块
/usr/local/python-3.11.2/bin/python3 -V
/usr/local/python-3.11.2/bin/python3
# 执行下面命令不报错既正常
>>import _ssl
>>
来源:https://blog.csdn.net/ye__mo/article/details/129436629
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
如何利用Pytorch计算三角函数
![](https://img.aspxhome.com/file/2023/7/79707_0s.png)
python 从list中随机取值的方法
利用Python编写一个简单的缓存系统
![](https://img.aspxhome.com/file/2023/7/90887_0s.webp)
Python with语句和过程抽取思想
ansible-playbook实现自动部署KVM及安装python3的详细教程
python 遍历pd.Series的index和value
pytorch中model.named_parameters()与model.parameters()解读
OpenCV每日函数之BarcodeDetector类条码检测器
![](https://img.aspxhome.com/file/2023/1/100791_1s.png)
浅谈python中频繁的print到底能浪费多长时间
python绘制箱型图
![](https://img.aspxhome.com/file/2023/6/127736_0s.jpg)
python读写二进制文件的方法
Python实现多项式拟合正弦函数详情
![](https://img.aspxhome.com/file/2023/7/103327_0s.png)
利用ctypes提高Python的执行速度
MySQL数据库root权限丢失解决方案
Python Pygame实战之打地鼠小游戏
如何判断发言是否为空?
PyTorch中关于tensor.repeat()的使用
浅析Python3爬虫登录模拟
使用Python操作PDF文件
![](https://img.aspxhome.com/file/2023/2/79552_0s.png)
python实现图片九宫格分割的示例
![](https://img.aspxhome.com/file/2023/3/99543_0s.png)