由于centos7 自带python版本太老,所以需要自己编译安装最新版本的python.

  1. 下载源代码
1
2
wget https://www.python.org/ftp/python/3.8.3/Python-3.8.3.tar.xz
tar -Jxvf Python-3.8.3.tar.xz
  1. 安装编译环境
1
2
yum groupinstall 'Development Tools'
yum install openssl-devel bzip2-devel expat-devel gdbm-devel sqlite-devel libffi-devel readline-devel
  1. 编译安装
1
2
3
4
cd Python-3.8.3
./configure --prefix=/usr/local/python3 --enable-shared CFLAGS=-fPIC
make
make install
  1. 建立软链接
1
2
ln -sv /usr/local/python3/bin/python3 /usr/bin/python3
ln -sv /usr/local/python3/bin/pip3 /usr/bin/pip3
  1. 添加动态库
1
2
3
4
5
6
7
8
新建 /etc/ld.so.conf.d/python.conf
添加如下内容:
    /usr/local/python3/lib
    /usr/lib
执行:
    ldconfig
查看结果:
    ldconfig -v