CentOS 7.6 默认安装了 Python 2.7.5
准备环境
yum install git gcc gcc-c++ make automake autoconf libtool pcre pcre-devel zlib zlib-devel openssl-devel wget vim -y
yum install libXcomposite libXcursor libXi libXtst libXrandr alsa-lib mesa-libEGL libXdamage mesa-libGL libXScrnSaver -y
yum install libffi-devel -y # Python3.7及以上版本需要安装libffi-devel,否则安装时会报错 ModuleNotFoundError: No module named ‘_ctypes’ 错误
下载
wget https://www.python.org/ftp/python/3.7.2/Python-3.7.2.tar.xz
解压
tar -xvJf Python-3.7.2.tar.xz
编译、安装
cd Python-3.7.2/ ./configure --enable-shared --prefix=/usr/local CFLAGS=-fPIC LDFLAGS="-Wl,-rpath /usr/local/lib" make -j24 make install
做软链接
ln -sf /usr/local/bin/python3.7 /usr/bin/python3 ln -sf /usr/local/bin/python3.7 /usr/bin/python3.7 ln -sf /usr/local/bin/pip3.7 /usr/bin/pip3 ln -sf /usr/local/bin/pip3.7 /usr/bin/pip3.7
测试安装结果:
python3 --version