网络编程
位置:首页>> 网络编程>> Python编程>> python3.10及以上版本编译安装ssl模块的详细过程

python3.10及以上版本编译安装ssl模块的详细过程

作者:伏逸  发布时间:2022-05-05 07:26:28 

标签:python3.10,ssl模块,安装

前言

由于python3.10之后版本不在支持libressl使用ssl,需要使用openssl安装来解决编译安装python时候遇到的ssl模块导入失败的问题,这里需要用的openssl1.1.1版本或者更高版本

python3.10及以上版本编译安装ssl模块的详细过程

编译安装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时候报错,查看对应文件显示模块缺少,需要加载导入模块

python3.10及以上版本编译安装ssl模块的详细过程

报错原因: 缺少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

python3.10及以上版本编译安装ssl模块的详细过程

退出界面回到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

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com