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
165 views
in Technique[技术] by (71.8m points)

python - See when packages were installed / updated using pip

I know how to see installed Python packages using pip, just use pip freeze. But is there any way to see the date and time when package is installed or updated with pip?

question from:https://stackoverflow.com/questions/24736316/see-when-packages-were-installed-updated-using-pip

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

1 Reply

0 votes
by (71.8m points)

If it's not necessary to differ between updated and installed, you can use the change time of the package file.

Like that for Python 2 with pip < 10:

import pip, os, time

for package in pip.get_installed_distributions():
     print "%s: %s" % (package, time.ctime(os.path.getctime(package.location)))

or like that for newer versions (tested with Python 3.7 and installed setuptools 40.8 which bring pkg_resources):

import pkg_resources, os, time

for package in pkg_resources.working_set:
    print("%s: %s" % (package, time.ctime(os.path.getctime(package.location))))

an output will look like numpy 1.12.1: Tue Feb 12 21:36:37 2019 in both cases.

Btw: Instead of using pip freeze you can use pip list which is able to provide some more information, like outdated packages via pip list -o.


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

...