how to print time took for each package in requirement.txt to be installed

Viewed 111

Is there any convenient way to print the time took for each package when running pip install -r requirements.txt?

I would like something like pip install -r requirement.txt --print-times and instead of just printing the names of the package and the versions I would like the output to look something like this:

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

etc...

I did not find this data under --verbose.

Thanks!


EDIT:

I'm aware of options like writing a bash/python scripts but I'm looking for a simple flag or single-line command.

2 Answers

I have a suggestions for you, you can use a python programm:

  • Open you requirement.txt (f = open('requirement.txt', 'r'))
  • Read the file (doc = f.readlines())
  • In a for loop take each lines
  • Initialise a timer (t0 = time.time())
  • Run pip install with pip package in python
  • Display the time it tooks (time.time() - t0)
  • Use an alias to replace run this script insteed of pip install

create a bash script with this content

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
Related