【python】脚本批量安装第三方包

编写脚本py程序

新建批量安装的文件 libsinstall.py

import os
# 添加需要安装的扩展包名称进去
libs = {"pillow" , "sklearn" , "numpy" , "pandas"}
try:
    for lib in libs:
        os.system(" pip install " + lib)
        print("{}   Install successful".format(lib))
except:
    print("{}   failed install".format(lib))

cmd命令行输入python batchinstall.py运行程序即可,忽略我的python3 是为了区分不同版本改名的。
在这里插入图片描述
安装的时候默认获取包的路径可能是国外的网站,速度很慢,可以设置更改为国内的镜像网站。
在C:\Users\你的用户名\AppData\Roaming路径下新建 pip 文件夹,在文件夹内新建 pip.ini 配置文件。输入:

[global] 
timeout = 6000 
index-url = http://mirrors.aliyun.com/pypi/simple/ 
trusted-host = mirrors.aliyun.com

也可以使用其他国内镜像网站,之前文章有介绍。

猜你喜欢

转载自blog.csdn.net/dzg_chat/article/details/83903397