由于工作需要,系统自带的 Python2.7 已经不能满足要求了,自己写了个安装脚本,自定义版本号然后执行即可。
#!/usr/bin/env bash
###############################################################################
# 安装Python 3
# Author : duliang <www.dba100.com>
# Desc : CentOS 7 通过
###############################################################################
PY_VERSION=3.7.4 # 版本号
if [ -d /usr/local/python3 ]; then
echo 'python3 already exists!'
exit
fi
yum install -y gcc gcc-c++
yum install -y zlib-devel openssl-devel
yum install -y wget
yum install -y libffi-devel # 解决Python3.7: ModuleNotFoundError: No module named '_ctypes'
yum install -y readline-devel # 解决Python命令行方向箭头移动问题
cd /usr/local/src
if [ ! -f Python-$PY_VERSION.tgz ]; then
wget -c https://www.python.org/ftp/python/$PY_VERSION/Python-$PY_VERSION.tgz
fi
tar zxvf Python-$PY_VERSION.tgz && cd Python-$PY_VERSION
./configure --prefix=/usr/local/python3
make && make install
ln -fs /usr/local/python3/bin/python3 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
mkdir ~/.pip
cat > ~/.pip/pip.conf << EOF
[global]
index-url = https://mirrors.aliyun.com/pypi/simple/
[install]
trusted-host=mirrors.aliyun.com
EOF
pip3 list