1.下载python3编译的依赖包
yum install -y gcc patch libffi-devel python-devel zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel
2.下载python包
wget https://www.python.org/ftp/python/3.12.3/Python-3.12.3.tgz
3.解压缩源码包
tar -zxvf Python-3.12.3.tgz
4.创建python的安装目录
mkdir -p /usr/local/python3
5.进入解压后的目录并且执行
cd Python-3.12.3
./configure --prefix=/usr/local/python3/
6.编译并安装
make && make install
7.添加环境变量
vi /etc/profile
在末尾添加
PATH=/usr/local/software/python/bin:$PATH
保存后执行
source /etc/profile
8.修改python的链接指向
mv /usr/bin/python3 /usr/bin/python3.bak
ln -s /usr/local/python3/bin/python3 /usr/bin/python3
转载自:https://blog.csdn.net/weixin_41133459/article/details/125316142
评论