Write your own python3 installation script

Python needs a unified python version when operating and maintaining a Linux cluster. Simply write a python installation script for unified installation. The machine needs to have an installation package source environment (network source/local source) python source package (download to local or online), source package The sohu python source package is recommended in China.
There is nothing technical about this script. It uses os.syetem to call a Linux command and judges whether it is successful or not based on the return value. Only the answer to the input_timeout_python question on stackoverflow is sought.

Use platform to judge the system version (different versions have different dependencies and installation methods)

if "redhat" in os_platform:
    print color_green("正在安装依赖包...")
    res = os.system(
        "yum -y install wget sqlite-devel xz gcc automake zlib-devel openssl-devel epel-release git > /dev/null  2>&1")
elif "Ubuntu" in os_platform:
    res = os.system(
        " apt-get -y install wget libkrb5-dev libsqlite3-dev gcc make automake libssl-dev zlib1g-dev libmysqlclient-dev libffi-dev git > /dev/null  2>&1")
else:
    print color_red("此脚本暂不支持此系统,{}".format(os_platform))
    sys.exit(1)

The input_timeout_on_python problem (this is a pit dug for yourself, colleagues who should install python should install ssl support)
Write your own python3 installation script
modify the code yourself as follows (reference ignored):

action = "yes" #默认值
timeout = 5
print color_green("请选择是否支持ssl,默认支持(yes/no)"),
rlist, _, _ = select([sys.stdin], [], [], timeout)
if rlist:
    action = sys.stdin.readline() #获取新的输入值(如果有)

Python3 supports ssl need to modify the Modules/Setup file, call the sed command to modify (the command is not familiar)

    os.system("sed -i '205s/^#//g' ./Python-3.6.2/Modules/Setup")
    os.system("sed -i '210s/^#//g' ./Python-3.6.2/Modules/Setup")
    os.system("sed -i '211s/^#//g' ./Python-3.6.2/Modules/Setup")
    os.system("sed -i '212s/^#//g' ./Python-3.6.2/Modules/Setup")

Set terminal font color with function


def color_red(context):
    return '\033[1;31;40m{}\033[0m'.format(context)

def color_green(context):
    return '\033[1;32;40m{}\033[0m'.format(context)

Reference: stackoverflow

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324915173&siteId=291194637