如何打印时间把在requirement.txt每个包进行安装

问题描述

是否有运行时,打印了为每个包的时间任何方便的方式pip install -r requirements.txt

我想是这样pip install -r requirement.txt --print-times 并且,而不是仅仅印刷包装和版本的名称,我想输出看起来是这样的:

Collecting shellescape==3.8.1
  Using cached shellescape-3.8.1-py2.py3-none-any.whl (3.1 kB)
  took 2.4 seconds
Collecting lxml==4.5.2
  Using cached lxml-4.5.2-cp38-cp38-manylinux1_x86_64.whl (5.4 MB)
    Collecting gevent==20.9.0
  Using cached gevent-20.9.0-cp38-cp38-manylinux2010_x86_64.whl (6.1 
  took 4.4 seconds

等等...

我没有找到下--verbose此数据。

谢谢!


编辑:

我所知,就像写一个bash / Python脚本的选择,但我在寻找一个简单的标志或单行命令。

解决方法

我给你一个建议,你可以使用python程序:

  • 打开你的requirement.txt (f = open('requirement.txt','r'))
  • 读取文件 (doc = f.readlines())
  • 在 for 循环中取每一行
  • 初始化计时器 (t0 = time.time())
  • 在 python 中使用 pip 包运行 pip install
  • 显示花费的时间 (time.time() - t0)
  • 使用别名代替运行此脚本而不是 pip install
,

用这个内容创建一个 bash 脚本

while IFS= read -r line; do
    start=`date +%s`
    pip install $line
    end=`date +%s`
    runtime=$((end-start))
    echo "took $runtime seconds"
done < requirements.txt

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...