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.
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.
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.
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))
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!
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
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]