1、先查看系统python所在位置
[root@localhost ~]# whereis python
python: /usr/bin/python /usr/bin/python2.7 /usr/lib/python2.7 /usr/lib64/python2.7 /etc/python /usr/include/python2.7
可确认系统原python环境在/usr/bin/
下。
2、进入/usr/bin/
cd /usr/bin/
3、先安装相关依赖
yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make
4、没有安装pip,需先添加epel扩展源
yum -y install epel-release
5、安装pip
yum install python-pip
6、下载python包(例如:Python3.10)
(注:若Linux环境网络好,可以直接下载;也可以通过其他方式下载后,在上传到Linux目录下)
wget https://www.python.org/ftp/python/3.10.9/Python-3.10.9.tgz
7、解压安装包
tar -xf Python-3.10.9.tgz
8、进入解压后的python目录,编译安装
cd Python-3.10.9
./configure prefix=/usr/local/python3
make && make install
9、安装依赖zlib、zlib-deve
yum install zlib zlib
yum install zlib zlib-devel
10、添加软连接
# 先备份原来的软连接
mv /usr/bin/python /usr/bin/python.bak
ln -s /usr/local/python3/bin/python3.10 /usr/bin/python
11、查看安装是否成功
python -V
完成!!!
标签:bin,python,zlib,devel,usr,install,linux,安装 From: https://www.cnblogs.com/lanjianhua/p/18366966