全网视频会员优惠活动
每日外卖红包会员优惠
全民淘
优惠一起淘

Centos系统一键升级python到2.7.9或3.7脚本 安装python3,并与Python2共存

各种红包天天领 云闪付大红包天天领 网购优惠券→ 淘宝 京东
淘宝发布QQ群:8808071 京东发布QQ群:259734197 线报互助QQ群:16723324
大流量推荐 电信打游戏 联通下载快 移动信号稳
每日外卖红包 饿了么 美团 美团外卖会员 饿了么会员 24小时线报轮播

很多centos自带python是2.X版本,正巧需要给机器升级python,于是网上找了如下脚本

直接使用:

wget -N --no-check-certificate https://cangshui.net/-down/-mysh/pythoninstall/centos6uppython.sh &&  chmod +x centos6uppython.sh && bash centos6uppython.sh

脚本预览:

echo "请输入序号选择你要干啥:  
输入1. 升级到Python 2.7.9 
输入2. 安装python3,,并与Python2共存
输入99. 直接删除python2.7和python3__危险!有可能使Yum将无法使用,知道vi /usr/bin/yum  自便
"  
  
value=0;  
  
read -p "请输入选项: " value  
  
case $value in  
    1) echo "升级python2.7.9"  
sleep 1s
# install some necessary tools & libs
echo "install some necessary tools & libs"
yum -y groupinstall "Development tools"
yum -y install openssl-devel zlib-devel ncurses-devel bzip2-devel readline-devel
yum -y install libtool-ltdl-devel sqlite-devel tk-devel tcl-devel
yum install -y readline readline-devel readline-static
yum install -y openssl openssl-devel openssl-static
yum install -y bzip2-devel bzip2-libs
sleep 5

# download and install python
version='2.7.9'
python_url="https://www.python.org/ftp/python/$version/Python-${version}.tgz"

# check current python version
echo "before installation, your python version is: $(python -V &2>1)"
python -V 2>&1 | grep "$version"
if [ $? -eq 0 ]; then
  echo "current version is the same as this installation."
  echo "Quit as no need to install."
  exit 0
fi

echo "download/build/install your python"
cd /tmp
wget --no-check-certificate $python_url
tar -zxf Python-${version}.tgz
cd Python-${version}
./configure
make -j 4
make install
sleep 5

echo "check your installed python"
python -V 2>&1 | grep "$version"
if [ $? -ne 0 ]; then
  echo "python -V is not your installed version"
  /usr/local/bin/python -V 2>&1 | grep "$version"
  if [ $? -ne 0 ]; then
    echo "installation failed. use '/usr/local/bin/python -V' to have a check"
  fi
  exit 1
fi
sleep 5

# install setuptools
echo "安装 setuptools"
wget --no-check-certificate https://bootstrap.pypa.io/ez_setup.py
python ez_setup.py
# check easy_install version
easy_install --version
sleep 5

# install pip for the new python
echo "正在用pip安装新的 python"
easy_install pip
# check pip version
pip -V

echo "安装完成"
echo "如果 'python -V' 仍然显示旧版本,可能需要重新运行脚本"
echo "然后/或者在 set /usr/local/bin 设置环境变量"
echo "----------------------------------------------------------------------------------------------------------"
echo "有问题请在   https://cangshui.net/?p=2198  评论区留言,我会尽可能的回复(忙的话就要等很久了呢。。。"
echo "----------------------------------------------------------------------------------------------------------"
wget -P /home https://cangshui.net/-down/-mysh/pythoninstall/pythonzijian.py
python /home/pythonzijian.py
rm -rf /home/pythonzijian.py
        ;;  
    2) echo "安装python3,,并与Python2共存"  
  sleep 1s
yum -y groupinstall 'Development Tools'
yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel
sleep 2s
wget https://www.python.org/ftp/python/3.7.0/Python-3.7.0b3.tar.xz
tar Jxvf Python-3.7.0b3.tar.xz
cd Python-3.7.0b3
./configure --prefix=/usr/local/python3
make && make install
echo 'export PATH=$PATH:/usr/local/python3/bin' >> ~/.bashrc
ln -sv /usr/local/python3/bin/python3.7 /usr/bin/python3
wget --no-check-certificate https://bootstrap.pypa.io/get-pip.py
python3 get-pip.py
echo "----------------------------------------------------------------------------------------------------------" 
echo "有问题请在 https://cangshui.net/?p=2198 评论区留言,我会尽可能的回复(忙的话就要等很久了呢。。。" 
echo "----------------------------------------------------------------------------------------------------------"
wget -P /home https://cangshui.net/-down/-mysh/pythoninstall/pythonzijian.py
python3 /home/pythonzijian.py
rm -rf /home/pythonzijian.py
        ;;  
   99) echo "卸载!"  
echo "正在卸载,请等待"
rm -rf /usr/local/bin/python2.7
rm -rf /usr/local/bin/python2.7-config
rm -rf /usr/local/lib/python2.7
echo "删除完成"
        ;; 
    *) echo "请你输入选项"
        exit 1  
        ;;  
esac

 

 收藏 (0) 打赏

您可以选择一种方式赞助本站

支付宝扫一扫赞助

微信钱包扫描赞助

未经允许不得转载:全民淘 » Centos系统一键升级python到2.7.9或3.7脚本 安装python3,并与Python2共存
分享到: 更多 (0)
切换注册

登录

忘记密码 ?

您也可以使用第三方帐号快捷登录

切换登录

注册

我们将发送一封验证邮件至你的邮箱, 请正确填写以完成账号注册和激活

饿了么每日领取大额红包

美团外卖每日领取大额红包

外卖会员优惠

饿了么中国银行立减10元-20元活动

9.9元抢饿了么超级吃货卡双月卡!

饿了么超级吃货卡年卡·仅39元

【美团外卖会员】 官方直充  月卡 季卡