美文网首页
2020-08-04 移植Python环境中的包

2020-08-04 移植Python环境中的包

作者: YPCHEN1992 | 来源:发表于2020-08-05 09:17 被阅读0次

    py_setup.sh

    #!/usr/bin/env bash
    
    # Function
    function usage() {
        echo "SYNOPSIS:"
        echo "    This Bash Script Was Written To Install Python Packages."
        echo "USAGE:"
        echo "    py_setup.sh requirement.yml"
        echo "YML:"
        echo "    pip freeze > requirement.yml"
        exit 1
    }
    
    # Check input requirement.txt
    if [[ $# != 1 ]]; then
        usage
    fi
    
    if [[ ! -e $1 ]]; then
        echo "[ERROR] Invalid requirement.yml"
        usage
    fi
    
    # Round 1
    for package in $(cat $1)
    do
        pip install ${package} -i https://pypi.tuna.tsinghua.edu.cn/simple/
        if [[ $? -eq 0 ]]; then
            echo ${package} >> py_setup.installed.txt
        else
            echo ${package} | sed 's/=.*$//' >>  py_setup.1round.failed.txt
        fi
    done
    
    # Round 2
    if [[ ! -e py_setup.1round.failed.txt ]]; then
        echo 'Python environment setup done!'
        exit 0
    else
        for packeage in $(cat py_setup.1round.failed.txt)
        do
            pip install ${package}
            if [[ $? -eq 0 ]]; then
                echo ${package} >> py_setup.installed.txt
            else
                echo ${package} | sed 's/=.*$//' >>  py_setup.2round.failed.txt
            fi
        done
    fi
    
    # Final check
    if [[ ! -e py_setup.2round.failed.txt ]]; then
        echo 'Python environment setup done!'
    else
        echo "[ERROR] Failed to indtall some package in py_setup.1round.failed.txt"
    fi
    exit 0
    

    有待修改

    相关文章

      网友评论

          本文标题:2020-08-04 移植Python环境中的包

          本文链接:https://www.haomeiwen.com/subject/cyuwrktx.html