查看何时使用pip安装/更新软件包 [英] See when packages were installed / updated using pip

查看:119
本文介绍了查看何时使用pip安装/更新软件包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道如何使用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安装/更新软件包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆