Python环境自动安装Python3.7
#!/bin/python # -*- coding: UTF-8 -*- import os import sys import platform from distutils.log import warn as printf def python_version(state): Edition = sys.version Num = Edition[0] if Num == "2": return raw_input(state) if Num == "3": return input(state) def linux_install(): printf("\n\t\t\t\t即将为您安装Python3.7...\n") system_update = python_version("系统是否升级 (yes/no).") django_install = python_version("是否安装Django (yes/no).") uwsgi_install = python_version("是否安装Uwsgi (yes/no).") Continue_install = python_version("是否开始安装Python (yes/no).") if system_update == "yes": printf("\nSystem preparation for upgrade...\n") os.system("yum -y update") printf("\nSystem upgrade completed...\n") if Continue_install == "yes": printf("\nCompile environment deployment...\n") os.system("sudo yum -y groupinstall \"Development tools\"") os.system( "sudo 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") printf("\nThe deployment of the compiled environment is complete...\n") if Continue_install == "yes": printf("\nPython download ...\n") os.system("mkdir /usr/local/python3_install") os.chdir("/usr/local/python3_install") os.system("wget https://www.python.org/ftp/python/3.7.0/Python-3.7.0a1.tar.xz") printf("\nPython download complete\n") if Continue_install == "yes": printf("\nPython ready to install\n") os.system("tar -xvJf Python-3.7.0a1.tar.xz") os.chdir("/usr/local/python3_install/Python-3.7.0a1") os.system("mkdir /usr/local/python3") os.system("./configure --prefix=/usr/local/python3 --enable-loadable-sqlite-extensions") os.system("sudo make") os.system("sudo make install") printf("\nPython installation completed\n") if Continue_install == "yes": printf("\nDelete temporary file\n") os.chdir("/usr/local/") os.system("rm -rf /usr/local/python3_install") if Continue_install == "yes": printf("\nCreating soft connections\n") os.system("ln -s /usr/local/python3/bin/python3 /usr/bin/python3") os.system("ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3") printf("Setup was successful") if django_install == "yes": os.system("pip3 install django") printf("Setup was successful") if uwsgi_install == "yes": os.system("pip3 install uwsgi") printf("Setup was successful") if python_version("是否进入Python3(yes/no)?") == "yes": os.system("python3") def UsePlatform(): category = platform.system() if category == "Windows": printf("Windows installation is not supported.\nhttps://www.python.org/ftp/python/") elif category == "Linux": linux_install() else: printf("Other System tasks") UsePlatform()