- 由于openssl出现问题,在源码编译安装python3的时候,会一直不成功,我测试了几个openssl的版本最后编译的时候都不能通过,最后根据python3给出的提示,安装了LibreSSL来代替openssl,LibreSSL是在看到openssl有问题的基础上开发出来的用来替代openssl的
#!/bin/bash
WORK_DIR=`mktemp -d`
#some Dependency software
yum install gcc make wget libffi-devel unzip zlib zlib-devel bzip2 bzip2-devel ncurses ncurses-devel readline readline-devel openssl -y
yum install openssl-devel openssl-static xz lzma xz-devel sqlite sqlite-devel gdbm gdbm-devel tk tk-devel git -y
downloadPip(){
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
}
downloadSetuptools(){
wget https://files.pythonhosted.org/packages/b0/d1/8acb42f391cba52e35b131e442e80deffbb8d0676b93261d761b1f0ef8fb/setuptools-40.6.2.zip
}
installLibreSSL(){
cd $WORK_DIR && [ ! -f $WORK_DIR/libressl-2.8.1.tar.gz ] && wget https://ftp.openbsd.org/pub/OpenBSD/LibreSSL/libressl-2.8.1.tar.gz
tar zxvf libressl-2.8.1.tar.gz && cd libressl-2.8.1
./configure --prefix=/opt/libressl && make install
mv /usr/bin/openssl /usr/bin/openssl.bak
mv /usr/include/openssl /usr/include/openssl.bak
ln -s /opt/libressl/bin/openssl /usr/bin/openssl
ln -s /opt/libressl//include/openssl /usr/include/openssl
echo "/opt/libressl/lib" > /etc/ld.so.conf.d/libressl.conf
ldconfig
}
installPython2(){
#get python2 and install python2
cd $WORK_DIR && [ ! -f $WORK_DIR/Python-2.7.15.tar.xz ] && wget https://www.python.org/ftp/python/2.7.15/Python-2.7.15.tar.xz
xz -d Python-2.7.15.tar.xz && tar -xvf Python-2.7.15.tar && cd Python-2.7.15
./configure --prefix=/opt/python2
make && make install && make clean && make distclean
#install setuptools
cd $WORK_DIR && [ ! -f $WORK_DIR/setuptools-40.6.2.zip ] && downloadSetuptools
unzip setuptools-40.6.2.zip && cd setuptools-40.6.2
/opt/python2/bin/python2 ./setup.py install
#install pip
cd $WORK_DIR && [ ! -f $WORK_DIR/get-pip.py ] && downloadPip
/opt/python2/bin/python2 $WORK_DIR/get-pip.py
}
installPython3(){
installLibreSSL
cd $WORK_DIR && [ ! -f $WORK_DIR/Python-3.7.1.tar.xz ] && wget https://www.python.org/ftp/python/3.7.1/Python-3.7.1.tar.xz
xz -d Python-3.7.1.tar.xz && tar -xvf Python-3.7.1.tar && cd Python-3.7.1
export LDFLAGS="-L /opt/libressl/lib"
export CPPFLAGS="-I /opt/libressl/include"
export PKG_CONFIG_PATH="/opt/libressl/lib/pkgconfig"
./configure --prefix=/opt/python3 --enable-shared CFLAGS=-fPIC ##--enable-optimizations 是优化选项(LTO,PGO 等)加上这个 flag 编译后,性能有 10% 左右的优化,但会花更多的时间
make && make install && make clean && make distclean
echo "/opt/python3/lib" > /etc/ld.so.conf.d/python3.conf
ldconfig
/opt/python3/bin/pip3 install --upgrade pip
}
echo -e "\033[31m Which python version do you want to install : \033[0m"
select var in "Python2" "Python3" "Python2andPython3" "Exit"
do
case $var in
"Python2")
installPython2
exit
;;
"Python3")
installPython3
exit
;;
"Python2andPython3")
installPython2
installPython3
exit
;;
"Exit")
exit
;;
*)
echo "Please chose 1 || 2 || 3 || 4"
;;
esac
done
#clear
cd && [ -d $WORK_DIR ] && rm $WORK_DIR -rf