centos7 shell脚本一键安装python3.7或3.8

post by rocdk890 / 2020-3-3 12:19 Tuesday linux技术
在上一篇文章centos7 shell脚本一键安装python3.7发布了之后,我同事看到了问我,你为什么不用python3.8,当时我就蒙了,对啊,还有人需要装3.8的版本的,今天对其进行了修改,让其支持安装python3.8,有需要的朋友可以看看.
系统:centos 7.x(64为)

cat /root/soft_shell/auto_install_python3.sh
#!/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
export PATH

# Check if user is root
if [ $(id -u) != "0" ]; then
    echo "Error: You must be root to run this script, please use root to initialization OS."
    exit 1
fi

version="3.7.4"
echo "Please enter the version number you need:"
read -p "(Default version: 3.7.4):" version
if [ "$version" = "" ];then
	version="3.7.4"
fi
name="Python"
pyfile="$name-$version.tgz"
check_ver=`echo $version|awk '{printf ("%3.1f\n",$1)}'`
dir="/usr/local/python3"

# Check if user is root
if [ $(id -u) != "0" ]; then
    echo "Error: You must be root to run this script, please use root to install"
    exit 1
fi

rpm=`rpm -qa libffi-devel|awk -F "-" '{print $1}'`
if [ -z $rpm ];then
	yum  -y install  wget gcc gcc-c++ make openssl-devel bzip2-devel libffi-devel
else
 	echo -e "\033[40;31m libffi [found]\033[40;37m"
fi

if [ -e $dir ];then
	rm -fr /usr/local/python3
	rm -rf /usr/bin/python3
	rm -rf /usr/bin/pip3
else
	echo -e "\033[40;31m python [no found]\033[40;37m"
fi

if [ -s $pyfile ];then
	echo -e "\033[40;31m $pyfile [found]\033[40;37m"
else
	wget https://www.python.org/ftp/python/$version/$pyfile
	tar zxf $pyfile
fi

cd $name-$version
./configure --prefix=/usr/local/python3 --enable-optimizations
make altinstall

if [ "$check_ver" = "3.7" ];then
	ln -s /usr/local/python3/bin/python3.7 /usr/bin/python3
	ln -s /usr/local/python3/bin/pip3.7 /usr/bin/pip3
elif [ "$check_ver" = "3.8" ];then
	ln -s /usr/local/python3/bin/python3.8 /usr/bin/python3
	ln -s /usr/local/python3/bin/pip3.8 /usr/bin/pip3
fi

if [ -d /root/.pip ];then
	echo -e "\033[40;31m file is [found]\033[40;37m"
else
	mkdir ~/.pip

cat > ~/.pip/pip.conf <<EOF
[global]
index-url = https://pypi.doubanio.com/simple/
[install]
trusted-host=pypi.doubanio.com
disable-pip-version-check = true
timeout = 6000
EOF
fi

pip3 install --upgrade pip

echo -e "\nInstalled Python and pip version is ... "
python3 -V && pip3 -V

echo -e "\033[32m \nInstall Successfully! \033[0m"
夜空- 本站版权
1、本站所有主题由该文章作者发表,该文章作者与夜空享有文章相关版权
2、其他单位或个人使用、转载或引用本文时必须同时征得该文章作者和夜空的同意
3、本帖部分内容转载自其它媒体,但并不代表本站赞同其观点和对其真实性负责
4、如本帖侵犯到任何版权问题,请立即告知本站,本站将及时予与删除并致以最深的歉意
5、原文链接:blog.slogra.com/post-767.html

标签: centos 安装 shell install 一键 python 自动

评论: