python安装脚本

#!/bin/bash

echo -e """\e[1;32m 以下为提示信息 \e[0m
1.这个脚本是干嘛的?

\e[31m此脚本能以源码的方式在您的主机上安装来自官方指定版本的python \e[0m 
2.前提条件?

\e[31m需要能联通外网
需要给与执行权限(如无特殊直接下载到/root/下,且最好使用source运行此脚本 \e[0m
3.如何使用?

\e[1;33m此脚本采用半交互式!
注意!看到版本提示时只需输入版本号然后回车(直接回车默认版本为3.8.3)
注意!安装位置请使用绝对路径如输入/opt/然后回车(直接回车默认为/usr/local/) \e[0m
如输入错误可强制结束脚本后重新运行!
......
"""
echo -e "\e[1;31m 开始安装步骤 \e[0m"
# 从输入读取变量至version
read -rp "你想要安装什么版本的python?:" version

if [ -z "$version" ]; then
  version=3.8.3
fi
# 与version类似
read -rp "你要将Python-$version安装在哪?:" install_dir

if [ -z "${install_dir}" ]; then
  install_dir=/usr/local/
fi

echo -e "\e[1;34m 请确认:5s后Python-$version将被安装在$install_dir \e[0m ......"

sleep 5

cd
#安装必要组件
yum -y install wget make

#配置阿里云epel源
if ! rpm -q epel-release; then
  yum install "https://mirrors.aliyun.com/epel/epel-release-latest-$(rpm -E '%{rhel}').noarch.rpm"
fi

#if [ -e "epel-release-latest-$(rpm -E '%{rhel}').noarch.rpm" ]; then
#  yum -y install *.rpm
#else
#  wget "https://mirrors.aliyun.com/epel/epel-release-latest-$(rpm -E '%{rhel}').noarch.rpm"
#  yum -y install *.rpm
#fi
# wget -O /etc/yum.repos.d/epel.repo https://mirrors.aliyun.com/repo/epel-7.repo

#安装依赖包
yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel libffi-devel
#安装编译工具
yum -y install gcc gcc-c++ kernel-devel

#下载Python源码包
#wget https://www.python.org/ftp/python/$version/Python-$version.tgz
wget https://registry.npmmirror.com/-/binary/python/$version/Python-$version.tgz

#解压
tar -zxvf Python-$version.tgz

cd "Python-$version" || exit 1

#开始编译
./configure --prefix=$install_dir"python$version"
make && make install

#创建软链接
#ln -s $install_dir"python$version"/bin/python${version%\.*} /usr/bin/python${version%\.*}
#ln -s $install_dir"python$version"/bin/pip${version%\.*} /usr/bin/pip${version%\.*}

#配置环境变量
echo "export PATH=$install_dir"python$version"/bin:\$PATH" >/etc/profile.d/python.sh

if ! which "python${version%\.*}"; then
  echo "python${version%\.*}安装完成"
  #删除包
  cd
  rm -rf Python-$version.tgz Python-$version
else
  echo """安装失败
  也许需要手动读取python环境变量
  source /etc/profile.d/python.sh
  """
fi
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值