centos 7 一键升级python 3脚本



#coding=utf-8
import subprocess
import os,sys
def exe_cmd(cmd):
    p = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
    while True:
        next_line = p.stdout.readline()
        return_line = next_line.decode("utf-8", "ignore")
        if return_line == '' and p.poll() != None:
            break
        print(return_line)
    stdout, stderr = p.communicate()
    if p.returncode != 0:
        return False
    return True
 
def main():
    print ("python 3.7.2 一键安装开始!")
    backinfo = exe_cmd('ping -c 1 -w 1 www.baidu.com')
    if backinfo == False:
        print ("网络检测失败程序退出,请重新检测网络环境!")
        sys.exit()
    print ("网络连接正常!")
    yum_jc = exe_cmd('yum list')
    if yum_jc == False:
        print ("yum 不可用,请先手动配置yum安装!")
        sys.exit()
    print ('yum安装检测可用!')
 
    exe_cmd("yum install gcc -y")
    exe_cmd("yum install openssl-devel bizp2-devel expat-devel gdbm-devel readline-devel sqlite-devel libffi-devel -y")
    exe_cmd("wget http://npm.taobao.org/mirrors/python/3.7.2/Python-3.7.2.tgz")
    exe_cmd("tar -zxvf Python-3.7.2.tgz")
    exe_cmd("mv Python-3.7.2 /usr/local/")
    exe_cmd("rm -rf Python-3.7.2.tgz")
    os.chdir('/usr/local/Python-3.7.2')
    exe_cmd("./configure")
    exe_cmd("make")
    exe_cmd("make install")
    exe_cmd("mv /usr/bin/python /usr/bin/python.bak")
    exe_cmd("ln -s /usr/local/bin/python3 /usr/bin/python")
    exe_cmd("mv /usr/bin/pip /usr/bin/pip.bak")
    exe_cmd("ln -s /usr/local/bin/pip3.7 /usr/bin/pip")
    print ("程序执行完成!输入 python -v 查看效果。")
  
if __name__ == '__main__':
    main()

 

whatangel

孤独的灵魂从来都不会死亡!

相关推荐

Leave a Reply

Your email address will not be published. Required fields are marked *

微信扫一扫,分享到朋友圈

centos 7 一键升级python 3脚本
返回顶部

显示

忘记密码?

显示

显示

获取验证码

Close