python通过pip install -r requirements.txt 安装包错误时,跳过改包的安装

通过 pip install -r requirements.txt 安装包时,有一个包安装错误,都安装不成功,通过脚本实现错误的包跳过安装。代码如下:

# -*- coding: utf-8 -*-
# @DATE : 2021/12/19
# @File : install_package.py
from subprocess import call


def install_package(python_env, pack_path):
    """
    :param python_env: python 环境
    :param pack_path: requirements.txt 的路径
    :return: install failed package
    """
    result = set()
    with open(pack_path, "r") as f:
        packs = f.readlines()
    for pack in packs[:1]:
        if not pack:
            continue
        try:
            call("%s -m pip install %s" % (python_env, pack), shell=True)
        except Exception:
            result.add(pack)
            continue
    return result
if __name__ == '__main__':
    install_package(r"D:\myvirtual\agency\Scripts\python","requirements.txt")
上一篇:题解 P7595 【猜树】&& P7597 【「EZEC-8」猜树 加强版】(交互,构造,dsu on tree)


下一篇:【iCore3 双核心板_FPGA】例程四:Tcl脚本实验——配置引脚