Python批量安装第三方库

Python批量安装第三方库


```python
import os  #引入os 库,os是python自带的库

#将要批量安装的第三方库写进一个列表
libs = ["numpy","matplotlib","pillow","sklearn","scipy","requests","jieba","pyspider",
        "quads","beautifulsoup4","wheel","networkx","sympy","pyinstaller","django",
        "flask","werobot","pyqt5","pandas","pyopengl","pypdf2","docopt","pygame"]

#使用try,expect结构运行,如果try部分出错,则执行except部分的代码
#对列表libs进行遍历,执行os.system命令
try:
    for lib in libs:
        os.system("pip install " + lib)
    print("安装成功")
except:
    print("安装失败")

#运行之后python会自动打开cmd窗口进行安装,请确保网络良好。

你可能感兴趣的:(PYTHON,python)