如何在CentOS 7 中基于OpenSSL 3.0 搭建Python 3.0 环境

1、OpenSSL
1.1 原因
shell 复制代码
[root@localhost ~]# openssl version
OpenSSL 1.0.2k-fips  26 Jan 2017
[root@localhost ~]#

通过执行openssl version可知Linux系统已经安装了OpenSSL,但该版本较低;Python 3 要求 OpenSSL版本不能低于1.1.1,否则安装Python3时提示如下信息:

1.2 依赖

原因:

①、下面下载的openssl-3.2.0.tar.gz和Python-3.10.9.tgz只是源码,需要先编译,才能安装,所以需要安装gcc编译器;

②、若不安装IPC::Cmd,则在执行./config --prefix=/usr/local/openssl-3.2.0时提示如下信息:

复制代码
Can't locate IPC/Cmd.pm in @INC (@INC contains: /opt/openssl-3.2.0/util/perl /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 . /opt/openssl-3.2.0/external/perl/Text-Template-1.56/lib) ...

安装:

shell 复制代码
[root@localhost ~]# yum -y install gcc perl-IPC-Cmd
1.3 安装

a、下载

浏览器访问https://www.openssl.org/source/,下载所需版本,这里下载3.2.0

b、上传

借助MobaXterm等工具将OpenSSL安装包上传至/opt目录;

c、解压

将JDK压缩文件解压至/opt目录:tar -xvf /opt/openssl-3.2.0.tar.gz -C /opt

d、删除

删除压缩文件:rm -f /opt/openssl-3.2.0.tar.gz

e、安装

shell 复制代码
[root@localhost ~]# cd /opt/openssl-3.2.0
[root@localhost openssl-3.2.0]# ./config
[root@localhost openssl-3.2.0]# make && make install

提示:

①、指令"make && make install"执行完毕大概需要10分钟。

②、执行./config指令时,可以通过--prefix 指定软件安装路径,为了简化Python3.0安装过程,这里忽略--prefix设置,如果指定了该设置则需要额外执行指令,设置OpenSSL路径,才能进一步安装Python3.0。

f、动态链接库

原因:

shell 复制代码
[root@localhost openssl-3.2.0]# openssl version
openssl: error while loading shared libraries: libssl.so.3: cannot open shared object file: No such file or directory

操作:

shell 复制代码
[root@localhost openssl-3.2.0]# echo "/usr/local/lib64" > /etc/ld.so.conf.d/openssl.conf
[root@localhost openssl-3.2.0]# ldconfig

说明:ldconfig 命令用于在/lib、 /usr/lib 和 /etc/ld.so.conf 目录搜索可共享的动态链接库(如 lib*.so*),进而创建动态链接器(ld.sold-linux.so)所需的缓存文件。该文件默认为 /etc/ld.so.cache,其保存了排好序的动态链接库名字列表。为了让动态链接库为系统所共享,需运行ldconfig 命令更新动态链接库的缓存文件。

1.4 检查
shell 复制代码
[root@localhost openssl-3.2.0]# openssl version
OpenSSL 3.2.0 23 Nov 2023 (Library: OpenSSL 3.2.0 23 Nov 2023)
[root@localhost openssl-3.2.0]#
2、Python
2.1 下载

通过https://www.python.org/ftp/python/下载Python安装包,这里下载[Python-3.10.9.tgz](https://www.python.org/ftp/python/3.10.9/Python-3.10.9.tgz);

2.2 上传

借助MobaXterm等工具将Python安装包上传至/opt目录;

2.3 解压

将JDK压缩文件解压至/opt目录:tar -xvf /opt/Python-3.10.9.tgz -C /opt

2.4 删除

删除压缩文件:rm -f /opt/Python-3.10.9.tgz

2.5 依赖

原因

编译安装Python期间需要诸如ncurses-devel和sqlite-devel等环境,否则提示如下信息:

安装

shell 复制代码
# yum -y install ncurses-devel sqlite-devel readline-devel zlib-devel libffi-devel bzip2-devel tk-devel gdbm-devel xz-devel
2.6 安装
shell 复制代码
# cd /opt/Python-3.10.9
# ./configure --prefix=/usr/local/python-3.10.9/
# make && make install

说明:指令"make && make install"执行完毕大概需要3分钟。

2.7 环境
shell 复制代码
# tee >> /etc/profile << EOF
export PATH=/usr/local/python-3.10.9/bin:$PATH
EOF
# source /etc/profile
2.8 检查
shell 复制代码
[root@localhost Python-3.10.9]# python3 -V
Python 3.10.9
[root@localhost Python-3.10.9]# pip3 install pymysql -i https://mirrors.aliyun.com/pypi/simple/
Looking in indexes: https://mirrors.aliyun.com/pypi/simple/
Collecting pymysql
  Downloading https://mirrors.aliyun.com/pypi/packages/e5/30/20467e39523d0cfc2b6227902d3687a16364307260c75e6a1cb4422b0c62/PyMySQL-1.1.0-py3-none-any.whl (44 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 44.8/44.8 kB 298.5 kB/s eta 0:00:00
Installing collected packages: pymysql
Successfully installed pymysql-1.1.0
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv

[notice] A new release of pip available: 22.3.1 -> 23.3.2
[notice] To update, run: pip3 install --upgrade pip
[root@localhost Python-3.10.9]#
相关推荐
鸿业远图科技1 分钟前
分式注记种表达方式arcgis
python·arcgis
别让别人觉得你做不到1 小时前
Python(1) 做一个随机数的游戏
python
小彭律师2 小时前
人脸识别门禁系统技术文档
python
张小九994 小时前
PyTorch的dataloader制作自定义数据集
人工智能·pytorch·python
zstar-_4 小时前
FreeTex v0.2.0:功能升级/支持Mac
人工智能·python·macos·llm
苏生要努力4 小时前
第九届御网杯网络安全大赛初赛WP
linux·python·网络安全
于壮士hoho4 小时前
DeepSeek | AI需求分析
人工智能·python·ai·需求分析·dash
蒙奇D索大4 小时前
【人工智能】自然语言编程革命:腾讯云CodeBuddy实战5步搭建客户管理系统,效率飙升90%
人工智能·python·django·云计算·腾讯云
AndrewHZ4 小时前
【Python生活】如何构建一个跌倒检测的算法?
python·算法·生活·可视化分析·陀螺仪·加速度计·跌倒检测
lizz6665 小时前
Python查询ES错误ApiError(406, ‘Content-Type ...is not supported
python·elasticsearch