一.装组件develop tools,以防止安装python出现依赖缺失
yum groupinstall "Development Tools"
yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel
二. 下载python
wget https://www.python.org/ftp/python/3.5.3/Python-3.5.3.tgz
三. 解压缩
tar -xvzf Python-3.5.3.tgz
cd Python-3.5.3
三. 编译
./configure --prefix=/usr/local --enable-shared
make
make install
四. 软链接
ln -s /usr/local/bin/python3 /usr/bin/python3
五.在运行Python之前需要配置库,否则会报如下类似错误
error while loading shared libraries: libpython2.7.so.1.0: cannot open shared object file: No such file or directory
echo /usr/local/lib >> /etc/ld.so.conf.d/local.conf
ldconfig
六.可选,删除之前编译python所需的包
yum groupremove "Development tools" --remove-leaveas
yum remove zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel --remove-leaves