[root@192 python3]# cat 1-install-python3.sh
set -e
#安装相关依赖
yum groupinstall -y "Development tools"
yum install -y zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel
yum install -y libffi-devel zlib1g-dev
yum install -y zlib*
yum install -y wget
#选择版本,默认为3.7.2
[[ $1 = '' ]] && edition=3.7.2 || edition=$1
wget https://www.python.org/ftp/python/${edition}/Python-${edition}.tar.xz
tar -xvJf Python-${edition}.tar.xz
mkdir /usr/local/python3
cd Python-${edition}
./configure --prefix=/usr/local/python3 --with-ssl
#./configure --prefix=/usr/local/python3 --enable-optimizations --with-ssl
#第一个指定安装的路径,不指定的话,安装过程中可能软件所需要的文件复制到其他不同目录,删除软件很不方便,复制软件也不方便.
#第二个可以提高python10%-20%代码运行速度. 此参数对gcc版本要求较高,版本低是会报错
#第三个是为了安装pip需要用到ssl,后面报错会有提到.
make && make install
#建立软连接
ln -s /usr/local/python3/bin/python3 /usr/local/bin/python3
ln -s /usr/local/python3/bin/pip3 /usr/local/bin/pip3
#测试是否正常安装
python3 -V
pip3 -V