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

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

前言

由于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

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

猜你喜欢

  • 如何利用Pytorch计算三角函数

    2021-01-27 11:35:47
  • python 从list中随机取值的方法

    2021-10-06 04:08:11
  • 利用Python编写一个简单的缓存系统

    2021-08-15 02:55:39
  • Python with语句和过程抽取思想

    2023-08-16 08:08:28
  • ansible-playbook实现自动部署KVM及安装python3的详细教程

    2021-09-02 23:13:12
  • python 遍历pd.Series的index和value

    2021-12-27 15:50:42
  • pytorch中model.named_parameters()与model.parameters()解读

    2023-02-03 23:47:36
  • OpenCV每日函数之BarcodeDetector类条码检测器

    2023-03-28 02:22:39
  • 浅谈python中频繁的print到底能浪费多长时间

    2022-01-31 06:24:34
  • python绘制箱型图

    2022-10-11 21:33:20
  • python读写二进制文件的方法

    2023-04-30 15:28:41
  • Python实现多项式拟合正弦函数详情

    2023-04-15 09:45:20
  • 利用ctypes提高Python的执行速度

    2023-11-04 22:33:55
  • MySQL数据库root权限丢失解决方案

    2008-07-13 13:59:00
  • Python Pygame实战之打地鼠小游戏

    2022-01-04 11:16:35
  • 如何判断发言是否为空?

    2010-01-12 20:15:00
  • PyTorch中关于tensor.repeat()的使用

    2023-06-26 07:13:35
  • 浅析Python3爬虫登录模拟

    2023-10-10 18:15:02
  • 使用Python操作PDF文件

    2022-01-01 06:15:12
  • python实现图片九宫格分割的示例

    2021-02-08 22:19:38
  • asp之家 网络编程 m.aspxhome.com