Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

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

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...