CentOS 7.9 额外安装一个Python3.x版本详细教程

Centos7默认的python版本是2.7,根据需要我们额外安装一个Python3.x版本。

1、安装基础环境

yum update -y
 
yum -y groupinstall "Development tools"
 
yum install openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel psmisc libffi-devel

2、下载Python3.x的tgz包

这里我以安装python3.9.1为例,其他版本只需改一下名称即可。

wget https://repo.huaweicloud.com/python/3.9.1/Python-3.9.1.tgz

3、开始安装

tar -xzf Python-3.9.1.tgz

cd Python-3.9.1

mkdir  /usr/local/python3/

./configure --prefix=/usr/local/python3 --with-ssl

make && make install

若报错:
/usr/bin/install: cannot change permissions of ‘/usr/local/python3/bin’: No such file or directory
Creating directory /usr/local/python3/lib
/usr/bin/install: cannot change permissions of ‘/usr/local/python3/lib’: No such file or directory
make: *** [altbininstall] Error 1
则执行:  sudo make altinstall

4、新增系统软链接

ln -sf /usr/local/python3/bin/python3.9 /usr/bin/python3
ln -sf /usr/local/python3/bin/pip3.9 /usr/bin/pip3

5、测试结果

pip3 -V
python3 -V

正常输出即安装成功。