先安装依赖包:
yum -y install bzip2 bzip2-devel ncurses openssl openssl-devel openssl-static xz lzma xz-devel sqlite sqlite-devel gdbm gdbm-devel tk tk-devel libffi-devel
wget https://www.python.org/ftp/python/3.7.1/Python-3.7.1.tar.xz ## 安装报错找不到 _ctype zlib 等模块 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 yum -y install gcc kernel-devel kenel-headers make bzip2 yum -y install readline-devel libffi-devel yum -y install e2fsprogs-devel uuid-devel libuuid-devel # 解压文件 tar -xvf Python-3.7.1.tar.xz # 进入到该文件夹 cd Python-3.7.1/ # --prefix 欲安装目录 ./configure --prefix=/usr/local/python3.7 --enable-optimizations # 编译安装,make时间比较长,大概需要15分钟 make make install rm -f /usr/bin/python3 ln -s /usr/local/python3.7/bin/python3.7 /usr/bin/python3 ln -s /usr/local/python3.7/bin/pip3 /usr/bin/pip3 # 还需要重新编译安装才有效