在编译安装一些python软件的时候,经常使用pip install -r requirements.txt 命令执行。如果其中一个库编译失败,会导致所有的库安装失败,非常费事费力。
于是写了一个py小脚本pipinstall.py,将库改为一个一个的安装,这样再碰到编译失败的,也不会影响其它的库,节省时间。
文件pipinstall.py代码
with open("requirements.txt", "r") as f:
xstr = f.readlines()
print(xstr)
import os
for i in xstr:
zstr = "pip install " + i.strip("\n") + " -i https://mirror.baidu.com/pypi/simple"
print(zstr)
os.system(zstr)
比如requirements.txt文件:
prettytable
tqdm
执行起来这样:
oot@863c89a419ec:~/github# python3 pipinstall.py
['prettytable\n', 'tqdm\n']
pip install prettytable -i https://mirror.baidu.com/pypi/simple
Looking in indexes: https://mirror.baidu.com/pypi/simple
Requirement already satisfied: prettytable in /usr/local/lib/python3.8/dist-packages (3.9.0)
Requirement already satisfied: wcwidth in /usr/local/lib/python3.8/dist-packages (from prettytable) (0.2.13)
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
pip install tqdm -i https://mirror.baidu.com/pypi/simple
Looking in indexes: https://mirror.baidu.com/pypi/simple
Requirement already satisfied: tqdm in /usr/local/lib/python3.8/dist-packages (4.66.1)
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
标签:baidu,prettytable,python,py,pypi,https,mirror,pip,安装
From: https://blog.csdn.net/skywalk8163/article/details/136665334