問題描述
我知道如何使用 pip 查看已安裝的 Python 包,只需使用 pip freeze
.但是有什么方法可以查看使用 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?
推薦答案
如果不需要區分更新和安裝,可以使用包文件的更改時間.
If it's not necessary to differ between updated and installed, you can use the change time of the package file.
就像 Python 2 一樣,帶有 pip <10:
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)))
或類似的更新版本(使用 Python 3.7 測試并安裝了帶有 pkg_resources
的 setuptools 40.8):
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))))
在這兩種情況下,輸出都將類似于 numpy 1.12.1: Tue Feb 12 21:36:37 2019
.
an output will look like numpy 1.12.1: Tue Feb 12 21:36:37 2019
in both cases.
順便說一句:您可以使用 pip list
而不是使用 pip freeze
,它能夠提供更多信息,例如通過 pip list -o代碼>.
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
.
這篇關于查看何時使用 pip 安裝/更新軟件包的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!