练习 py-shelll
#coding=utf-8
import os,sys
if os.getuid() == 0:
pass
else:
print('当前用户不是root,请以root用户执行脚本')
sys.exit(1)
version = input('请输入您想安装的python版本(2.7/3.7)')
if version == '2.7':
url = 'https://www.python.org/ftp/python/2.7.16/Python-2.7.16.tgz'
elif version == '3.7':
url = 'https://www.python.org/ftp/python/3.7.2/Python-3.7.2.tgz'
else:
print('您输入的版本号有误,请输入2.7或者3.7')
sys.exit(1)
cmd = 'wget '+url
res = os.system(cmd)
if res != 0:
print('downloading fail,please network')
sys.exit(1)
if version == '2.7':
package_name = 'Python-2.7.16'
else:
pachage_name = 'Python-3.7.2'
cmd = 'tar xf '+package_name+'.tgz'
res = os.system(cmd)
if res != 0:
os.system('rm '+package_name+'.tgz')
print('tar fail,please downloading again')
sys.exit(1)
cmd = 'cd '+package_name+' && ./configure --prefix=/usr/local/python && make && make install'
res = os.system(cmd)
if res != 0:
print('编译python源码失败,请检查是否缺少依赖库')
sys.exit(1)