- 首先需要安装GCC编译器来编译python3,其次需要依赖文件:
yum -y install gcc
yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel libffi-devel
如果有就不必下载了
- 下载压缩包,解压,编译安装
cd /usr/local
wget https://mirrors.huaweicloud.com/python/3.8.0/Python-3.8.0.tgz
tar -zxvf Python-3.8.0.tgz
mkdir /usr/local/python38
cd Python-3.8.0
./configure --prefix=/usr/local/python38
make && make install
- 建立软链接,以代替环境变量的创建
ln -s /usr/local/python38/bin/python3.8 /usr/bin/python3
ln -s /usr/local/python38/bin/pip3.8 /usr/bin/pip3
- 测试
python3 --version
pip3 --version
- 写在最后
centos自带的python环境是python2,所以目的是两个版本并存,使用3的时候,使用pip3/python3命令即可。