视频教程:https://www.bilibili.com/video/BV1Qe411y7Ca/?spm_id_from=333.999.0.0
1、下载
通过https://www.python.org/ftp/python/下载Python安装包,这里下载Python-3.10.9.tgz;
2、上传
借助MobaXterm等工具将Python安装包上传至/opt目录;
3、解压
将JDK压缩文件解压至/opt目录:tar -xvf /opt/Python-3.10.9.tgz -C /opt
4、删除
删除压缩文件:rm -f /opt/Python-3.10.9.tgz
5、依赖
原因:
①、Python-3.10.9.tgz只是Python源码,需要先编译,才能安装,所以需要安装gcc;
②、编译安装Python期间需要诸如ncurses-devel和sqlite-devel等环境,否则提示如下信息:
安装:
# yum -y install gcc ncurses-devel sqlite-devel readline-devel zlib-devel libffi-devel bzip2-devel tk-devel gdbm-devel xz-devel
6、OpenSSL
原因:
安装Python 3 前必须先安装OpenSSL,否则编译安装Python3时提示如下信息:
安装:
# yum -y install epel-release
# yum -y install openssl-devel openssl11 openssl11-devel
# 设置最新openssl库编译环境
# export CFLAGS=$(pkg-config --cflags openssl11)
# export LDFLAGS=$(pkg-config --libs openssl11)
注意:
必须先执行yum -y install epel-release,再执行yum -y install openssl11-devel,两条yum命令不要合起来一起执行,否则执行export命令时提示No package ‘openssl11’ found错误。文章来源:https://www.toymoban.com/news/detail-808377.html
7、安装
# cd /opt/Python-3.10.9
# ./configure --prefix=/usr/local/python-3.10.9/
# make && make install
说明:–prefix 指定软件安装路径文章来源地址https://www.toymoban.com/news/detail-808377.html
8、环境
# tee >> /etc/profile << EOF
export PATH=/usr/local/python-3.10.9/bin:$PATH
EOF
# source /etc/profile
9、检查
[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]#
到了这里,关于如何在CentOS 7 中基于OpenSSL 1.0 搭建Python 3.0 环境的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!