iis服务器助手广告广告
返回顶部
首页 > 资讯 > 后端开发 > Python >python3.10及以上版本编译安装ssl模块
  • 404
分享到

python3.10及以上版本编译安装ssl模块

sslperlpython 2023-09-03 09:09:17 404人浏览 安东尼

Python 官方文档:入门教程 => 点击学习

摘要

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

前言

  由于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.gzhttps://www.openssl.org/source/openssl-1.1.1s.tar.gzhttps://www.openssl.org/source/openssl-3.0.7.tar.gz

编译安装

注:编译之前请先确保系统中安装了make以及GCc的软件包。,编译安装前确认/usr/include/openssl//为空
tar -zxf openssl-1.1.1s.tar.gzcd openssl-1.1.1s/./config -fPIC --prefix=/usr/include/openssl enable-sharedmakemake install

其中:
 -fPIC: 位置无关代码
 --prefix=: 路径 一般选 /usr/include/openssl
 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 configuremkdir /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/opensslmake -j 4make 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

--结束END--

本文标题: python3.10及以上版本编译安装ssl模块

本文链接: https://www.lsjlt.com/news/391990.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作