Centos 7 安裝python 版本
阿新 • • 發佈:2018-01-26
檢查 oot -- 源碼包 uid 輸入 .py inpu mod #!/root/.pyenv/shims/python #python 3.0
# -*- coding:UTF-8 -*-
import os
import sys
if os.getuid() == 0:
print("當前登錄客戶端ip地址如下")
os.system("who|awk '{print $5}'|cut -c 2-14")
else:
print("當前用戶不是root用戶,請使用root用戶執行此腳本")
sys.exit(1)
version = input("請輸入你想安裝的python 版本(2.7|3.5|3.7)")
if version == '2.7':
url = 'https://www.python.org/ftp/python/2.7/Python-2.7.tgz'
cmd = 'yum -y install gcc* make cmake'
res = os.system(cmd)
if res != 0:
print("依賴包安裝失敗程序即將停止")
sys.exit(1)
elif version == '3.5':
url = 'https://www.python.org/ftp/python/3.5.2/Python-3.5.2rc1.tgz'
cmd = 'yum -y install gcc* make cmake'
res = os.system(cmd)
if res != 0:
print("依賴包安裝失敗程序即將停止")
sys.exit(1)
elif version == '3.7':
url = 'https://www.python.org/ftp/python/3.7.0/Python-3.7.0a4.tgz'
cmd = 'yum -y install gcc* make cmake'
res = os.system(cmd)
if res != 0:
print("依賴包安裝失敗程序即將停止")
sys.exit(1)
else:
print("您輸入的版本號有誤,請輸入2.7和3.5或者3.7")
sys.exit(1)
cmd = " wget " + url
res = os.system(cmd)
if res != 0:
print("下載源碼包失敗,請檢查網絡")
sys.exit(1)
if version == '2.7':
package_name = "Python-2.7"
elif version == '3.5':
package_name = "Python-3.5.2rc1"
else:
package_name = "Python-3.7.0a4"
cmd = 'chmod a+x ' + package_name +'.tgz'
os.system(cmd)
cmd = 'tar -xf ' + package_name +'.tgz'
res = os.system(cmd)
if res != 0:
os.system('rm '+ package_name +'.taz')
print("解壓源碼包失敗,請重新運行腳本下載")
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)
Centos 7 安裝python 版本