13

I would like to find a way to get the calendar date and time in hour:minute:seconds format for my packages installed via pip.

I would like to be able to see something in output like: Month/Day/Year - Hour:Minute:Seconds for each package.

vvvvv
  • 25,404
  • 19
  • 49
  • 81
wgwz
  • 2,642
  • 2
  • 23
  • 35

6 Answers6

9

Is this what you are looking for -

import pip
import os
import time

In [139]: for package in pip.get_installed_distributions():
   .....:          print "%s: %s" % (package, time.ctime(os.path.getctime(package.location)))
   .....:     
pyudev 0.17.dev20150317: Tue Mar 17 12:02:58 2015
python-magic 0.4.6: Fri Mar 20 14:07:59 2015
runipy 0.1.0: Fri Oct 31 01:49:34 2014

Source of the code - https://stackoverflow.com/a/24736563/170005

You can do import pip too, which is pretty interesting. I didn't know this.

Community
  • 1
  • 1
fixxxer
  • 15,568
  • 15
  • 58
  • 76
  • This is really cool. Thanks for the answer. The trouble is that I updated all of my installed packages at the same time on Mon Apr 27 15:22:11 2015. "ctime" is picking only that up at the moment. I'm going to check out some more os.path options to see if there is another time option. – wgwz Jun 02 '15 at 14:55
  • It seems like the only other options are `os.path.getatime` or `getmtime` which return last access time and last modification time. Which don't return the install date. But still damn close! – wgwz Jun 02 '15 at 15:09
  • 1
    @wgwz Unfortunately the problem is that package.location gives the directory where the package is installed rather than the path to the package itself. Here is an answer that works better for me: https://stackoverflow.com/a/44436961/2525237 – sunyata Dec 12 '17 at 22:32
  • Any idea to do the same outside of python? With some tool like `freeze` but that retrieve more info? – Juan Antonio Jun 14 '18 at 18:55
9

As of version 10.0.0 the get_installed_distributions() is not accessible from its previous location.

Although it is not recommended to use pip as a module inside your program, sometimes -like this question- it makes things much easier!

So, I searched the libraries a bit and found where it is hiding :) Here is the @fixxxer's answer according to new API and compatible with Python 3.x:

import os
import time
from pip._internal.utils.misc import get_installed_distributions

for package in get_installed_distributions():
    print ("{}\t{}".format(time.ctime(os.path.getctime(package.location)), package))
Dark
  • 413
  • 5
  • 8
7

Get much more than just date & time, but also install method, using pip-date

enter image description here

Gaia
  • 2,872
  • 1
  • 41
  • 59
  • For me `pip-date` is *opening* a python file instead of running, so I have to: (1) activate my conda environment, then (2) python c:\Users\myuser\miniconda3\envs\myenv\Scripts\pip-date.py. also (3) for Windows, run all this under ConEmu in order to see colors correctly – ishahak Jun 08 '22 at 09:40
1

You can list all the locations that holds the packages and then just list all the files in these directories (together with the creation time):

import pip
import os
import time

pkg_location_dir_strset = set()

for pip_pkg in pip.get_installed_distributions():
    if pip_pkg.location not in pkg_location_dir_strset:
        pkg_location_dir_strset.add(pip_pkg.location)

for pkg_location_dir_str in pkg_location_dir_strset:
    print("")
    print("Directory: " + pkg_location_dir_str)
    for file_or_dir in os.listdir(pkg_location_dir_str):
        # print("file_or_dir = " + file_or_dir)
        file_or_dir_path = os.path.join(pkg_location_dir_str, file_or_dir)
        print(
            os.path.basename(file_or_dir).ljust(50)
            + " " + time.ctime(os.path.getctime(file_or_dir_path))
        )

Also check out this answer for an alternative solution which you may prefer

Hope this helps!

sunyata
  • 1,843
  • 5
  • 27
  • 41
0

pip-date works like a charm, adding to it in case you want to get that output in the form of a text file

pip-date >packagelist.txt
Shreyas H.V
  • 109
  • 1
  • 3
  • Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center. – Tapan Hegde Oct 20 '21 at 14:41
0

Pip doesn't provide you with that option (yet). The easy way with no coding requirement to go about this is to find the path to your installed packages on your computer and check the date and time the folder was created/modified. The standard path is usually like:

 Users\[whatever_username]\AppData\Roaming\Python\Python[3.x]
Zia
  • 389
  • 1
  • 3
  • 17