Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
263 views
in Technique[技术] by (71.8m points)

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

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...