日常查看Python库的本地安装信息及pip库的使用方法(补tensorflow2.3.0所有依赖whl)

Posted 囚生CY

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了日常查看Python库的本地安装信息及pip库的使用方法(补tensorflow2.3.0所有依赖whl)相关的知识,希望对你有一定的参考价值。

序言

需求源于想要对每次执行pip installconda install命令来安装Python库做个日志记录, 并且想要对Anaconda根目录下的生成文件情况做个记录;

原因是最近发现很多Python库的更新太频繁, 前几天刚装的torchvision就出了0.8.0版本; 而且一个库还会有许多不同版本, 就dgl库(一个绘图库, 可以对知识图谱以及各种图神经网络进行可视化)而言, 目前除了一个非CUDA版本的dgl库, 其他的CUDA版本如dgl-cu100, dgl-cu101, dgl-cu102, dgl-cu90, dgl-cu92就有五个对应不同CUDA版本的dgl库, 之后CUDA版本更新肯定会变得更多, 虽然在安装时需要指定pip install dgl-cuXXX, 然而调用起来都是一样的import dgl, 这实在是乱套了; 不管是以后升级更新, 还是卸载非CUDA版本安装新的CUDA版本的库, 虽然使用pip install --upgradepip uninstall一般都能顺利完成, 但是如果能做个日志记录下每次安装的库总归是好的, 万一以后安装失败也有据可考;

这边顺手提供一些比较快的镜像库:

  • torchtorchvision所有版本的wheel安装包官方镜像库: https://download.pytorch.org/whl/torch_stable.html
  • pip所有的wheel安装库国内镜像(下载速度很快, 安装包非常全, 但是没有做分页致使镜像页加载很慢):
  • 这六个国内镜像库速度确实很快, 但是问题时它们都没有做分页, 所以点进去一个页面上有几十万个库链接, 一行只有一个, 所以加载特别慢, 找到自己要下载的库很费时间, 一个办法是写个爬虫去访问这个镜像URL, 响应是非常快的, 然后找到自己库的URL点进去就很快了;

事实上E:\\Anaconda3\\Lib\\site-packages下已经包含了相当完善的库安装信息;

关于查看每个安装包的安装信息, 可以查看E:\\Anaconda3\\Lib\\site-packages目录下命名中带有dist-info的文件夹里的信息:

  • direct_url.json: 如果有该文件, 则其中包含了安装包的位置(本地或线上);
    • 一般来说如果是用conda命令安装的库, 安装包的位置是一个无效的本地路径;
    • 如果时pip安装的离线wheel安装包, 则会记录当时wheel安装包的本地路径;
  • INSTALLER: 记录了安装的方法, 一般为pipconda;
  • METADATA: 记录了该库的元信息, 如库版本, 以及一些可能的说明事项, 起到README的功能;
  • RECORD: 记录了该库在安装时所有生成文件的路径, 很可能在执行pip uninstall命令时就是根据这个RECORD进行文件的删除;
    • 查看E:\\Anaconda3\\Lib\\site-packages\\torch-1.6.0.dist-info\\RECORD, 发现:
      • 安装torch时还安装了caffe2;
      • 并向E:\\Anaconda3\\Scripts目录下生成了两个可执行应用程序:
        • convert-caffe2-to-onnx.exe
        • convert-onnx-to-caffe2.exe;
    • 查看E:\\Anaconda3\\Lib\\site-packages\\opencv_python-4.4.0.46.dist-info\\RECORD, 发现:
      • Python中安装opencv库时, 本质上是在安装cv2库;
  • top_level.txt: 记录了安装该库时在E:\\Anaconda3\\Lib\\site-packages下所新建的目录, 如上面提到的torchtop_level.txt中记录了torchcaffe2, opencv则在top_level.txt中记录了cv2;
  • 其余如LICENSE, REQUESTED, WHEEL等文件没有包含很重要的信息, 略过;

注意到pip库提供了调用这些信息的接口, 方法如下

from pip._internal.utils.misc import get_installed_distributions

for package in get_installed_distributions():
	print(package)
	for line in package._get_metadata('RECORD'):
		print('  - '.format(line))

输出结果:

zipp 3.4.0
  - __pycache__/zipp.cpython-38.pyc,,
  - zipp-3.4.0.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4
  - zipp-3.4.0.dist-info/LICENSE,sha256=2z8CRrH5J48VhFuZ_sR4uLUG63ZIeZNyL4xuJUKF-vg,1050
  - zipp-3.4.0.dist-info/METADATA,sha256=noSfks-ReGCmOSTxll7TELBJy0P_yAvVLa0FCFyhMeM,2134
  - zipp-3.4.0.dist-info/RECORD,,
  - zipp-3.4.0.dist-info/REQUESTED,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
  - zipp-3.4.0.dist-info/WHEEL,sha256=EVRjI69F5qVjm_YgqcTXPnTAv3BfSUr0WVAHuSP3Xoo,92
  - zipp-3.4.0.dist-info/direct_url.json,sha256=iCXL0VBE1-8g3pxVtHjuR5iCqnBPkwsB2QYNQrLezZE,77
  - zipp-3.4.0.dist-info/top_level.txt,sha256=iAbdoSHfaGqBfVb2XuR9JqSQHCoOsOtG6y9C_LSpqFw,5
  - zipp.py,sha256=wMSoYxAIPgYnqJAW0JcAl5sWaIcFc5xk3dNjf6ElGgU,8089
zict 0.1.3
xlwt 1.3.0
xlwings 0.11.8
XlsxWriter 1.1.0
  - ../../Scripts/vba_extract.py,sha256=l4xfS_QQ48Gk0eWKCoCLnLYUlVOkCBcYZqD0BiQklBA,1943
  - XlsxWriter-1.1.0.dist-info/METADATA,sha256=K93U4KV4-I12RTmRFnbct55TMPHjMT-CuD1DrRA4o9M,2562
  - XlsxWriter-1.1.0.dist-info/RECORD,,
  - XlsxWriter-1.1.0.dist-info/WHEEL,sha256=CG516Me1TEyQqkQMqQpnDadrWi7ujPk88poSAu3OliQ,116
  - XlsxWriter-1.1.0.dist-info/top_level.txt,sha256=xFEUcpcY7QzAr_-ztkXebEt1FZCxpuCbmyCsBaevhRk,11
  - xlsxwriter/__init__.py,sha256=12nsSkasIrRdZ5ONbh4WqONjKbzDClN3TDtsMOFZ0Lo,79
  - xlsxwriter/app.py,sha256=cGxMrPn9MSjhhsl2aEE02-cMtFwyXailrerPTreBX1s,5739
...
...
...
...

目录


1 pip list 常规记录

执行pip list命令可以查看到本机中使用pip指令安装的所有库, 笔者发现其实使用conda install安装的库也会被列进来, 但是pip list并不能给到每个库的具体安装时间; 下面的代码给出了一种利用序言中提到的top_level.txt文件, 来列出pip list中所有库安装时间的信息(其中时间是该库最近一次被更新的时间):

# -*- coding: UTF-8 -*-
# @author: caoyang
# @email: caoyang@163.sufe.edu.cn

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

packages = []
for package in get_installed_distributions():
	package_name_version = str(package)
	try:
		module_dir = next(package._get_metadata('top_level.txt'))
		package_location = os.path.join(package.location, module_dir)
		os.stat(package_location)
	except (StopIteration, OSError):
		try:
			package_location = os.path.join(package.location, package.key)
			os.stat(package_location)
		except:
			package_location = package.location
	modification_time = os.path.getctime(package_location)
	modification_time = datetime.fromtimestamp(modification_time)
	packages.append([
		modification_time,
		package_name_version
	])

print('|Time|Package|')
print('|----|----|')
for modification_time, package_name_version in sorted(packages):
	print("|||".format(modification_time, package_name_version))

注意pip升级到20.x.x版本(大概…)后get_installed_distributions函数时被放到了pip._internal.utils.misc模块下, 否则直接调用pip.get_installed_distributions即可;

执行结果如下所示:


这是按照时间顺序列出地, 其实从时间可以很明显地看出, 从pip库往上都是安装Anaconda时顺带安装地库, 而后面的一些库就是笔者手动安装的包, 当然有的包可能并没有专门手动安装, 而是在安装其他包时由于依赖关系而绑定安装得到的; 还有一些未知的可能是PyCharm偷偷给装上的, 因为之前没有做日志, 可以手动把每个包安装的原因和方式记录在后面:

TimePackageNote
2020-11-03 14:30:07.677642pip 20.2.4
2020-11-03 14:43:00.483601selenium 3.141.0pip install selenium;
2020-11-03 15:31:07.884418opencv-python 4.4.0.46pip install opencv;
2020-11-15 13:27:43.735452conda-package-handling 1.7.2与安装torch相关;
2020-11-15 13:27:49.879591torch 1.6.0conda install torch;
2020-11-16 18:07:10.186186pyreadline 2.1未知;
2020-11-16 18:07:10.232195pyrsistent 0.17.3未知;
2020-11-16 18:07:11.093984fsspec 0.8.3未知;
2020-11-16 18:07:11.112187joblib 0.17.0未知;
2020-11-16 18:07:11.201223json5 0.9.5未知;
2020-11-16 18:07:11.207223mock 4.0.2未知;
2020-11-16 18:07:11.212224libarchive-c 2.9未知;
2020-11-16 18:07:11.219226soupsieve 2.0.1未知;
2020-11-16 18:07:11.844612importlib-metadata 2.0.0未知;
2020-11-16 18:07:11.857615jupyterlab-server 1.0.0未知;
2020-11-16 18:07:13.768216tensorly 0.5.0GitHub@RE2RNN 项目代码request, conda install tensorly;
2020-11-16 18:12:28.232559antlr4-python3-runtime 4.8未知;
2020-11-16 18:12:28.546880automaton-tools 0.1.8GitHub@RE2RNN 项目代码request, 这个是装错库了, 应该是要安装automata-tools的; pip install automata;
2020-11-16 18:27:40.146158pydash 4.9.0GitHub@RE2RNN 项目代码request;
2020-11-16 18:31:36.487373automata-tools 2.0.1GitHub@RE2RNN 项目代码request, 有穷状态自动机相关操作库; pip install automata;
2020-11-19 15:23:54.801501jupyter-contrib-core 0.3.3可能与jupyter-nbextensions-configurator安装相关;
2020-11-19 15:23:54.801501jupyter-highlight-selected-word 0.2.0可能与jupyter-nbextensions-configurator安装相关;
2020-11-19 15:23:54.812136jupyter-latex-envs 1.4.6可能与jupyter-nbextensions-configurator安装相关;
2020-11-19 15:23:54.844033jupyter-nbextensions-configurator 0.4.1jupyter的目录插件: pip install jupyter_contrib_nbextensions, 周围相关的几个jupyter包似乎都是很早就存在的, 更新日期在附近可能都是跟该插件的安装有关;
2020-11-19 15:23:54.865447jupyter-contrib-nbextensions 0.5.1可能与jupyter-nbextensions-configurator安装相关;
2020-11-26 10:41:46.104553torchvision 0.7.0发现之前安装torch时没有绑定安装torchvision, 在https://download.pytorch.org/whl/torch_stable.html 下载的whl文件手动pip安装的;
2020-11-26 10:41:47.136441future 0.18.2torchvision安装相关;
2020-11-30 12:44:06.155658dgl 0.5.2pip install dgl-0.5.2-cp37-cp37m-win_amd64.whl;

因为该脚本的输出是按照时间顺序输出的, 并且是最近修改的时间, 所以可以按日做个增量日志备份, 便于以后出问题查找, 再不济也是记录一下到底是为什么装了这个库, 以后看到至少能明明白白…

这玩意儿看起来似乎没有太大用处, 主要笔者现在强迫症晚期, 笔记本里装了什么东西都一定要搞得明明白白, 绝不允许一些莫名其妙的垃圾跑进了圣洁的固态硬盘上…


3 conda install 与 pip install 命令执行记录

# TODO

计划将每次执行的pip installconda install命令记录下来, 备查;


附录A 20201103 安装Anaconda3时自动安装的库

TimePackage
2018-09-04 21:09:52path.py 11.1.0
2020-11-03 11:57:00.282130PySocks 1.6.8
2020-11-03 11:57:00.282130PyYAML 3.13
2020-11-03 11:57:00.282130appdirs 1.4.3
2020-11-03 11:57:00.282130contextlib2 0.5.5
2020-11-03 11:57:00.282130cycler 0.10.0
2020-11-03 11:57:00.282130decorator 4.3.0
2020-11-03 11:57:00.282130entrypoints 0.2.3
2020-11-03 11:57:00.282130filelock 3.0.8
2020-11-03 11:57:00.282130greenlet 0.4.15
2020-11-03 11:57:00.282130heapdict 1.0.0
2020-11-03 11:57:00.282130imagesize 1.1.0
2020-11-03 11:57:00.282130ipython-genutils 0.2.0
2020-11-03 11:57:00.282130itsdangerous 0.24
2020-11-03 11:57:00.282130jdcal 1.4
2020-11-03 11:57:00.282130jupyter 1.0.0
2020-11-03 11:57:00.282130jupyter-core 4.4.0
2020-11-03 11:57:00.282130kiwisolver 1.0.1
2020-11-03 11:57:00.282130mccabe 0.6.1
2020-11-03 11:57:00.282130mistune 0.8.3
2020-11-03 11:57:00.282130pandocfilters 1.4.2
2020-11-03 11:57:00.282130pep8 1.7.1
2020-11-03 11:57:00.282130pickleshare 0.7.4
2020-11-03 11:57:00.282130pycodestyle 2.4.0
2020-11-03 11:57:00.282130pycosat 0.6.3
2020-11-03 11:57:00.282130pycrypto 2.6.1
2020-11-03 11:57:00.282130pycurl 7.43.0.6
2020-11-03 11:57:00.282130pyodbc 4.0.24
2020-11-03 11:57:00.282130pyparsing 2.2.0
2020-11-03 11:57:00.282130pytest-astropy 0.4.0
2020-11-03 11:57:00.282130pywin32 223
2020-11-03 11:57:00.282130ruamel-yaml 0.15.46
2020-11-03 11:57:00.282130simplegeneric 0.8.1
2020-11-03 11:57:00.282130singledispatch 3.4.0.3
2020-11-03 11:57:00.282130six 1.11.0
2020-11-03 11:57:00.282130threadpoolctl 2.1.0
2020-11-03 11:57:00.282130win-inet-pton 1.0.1
2020-11-03 11:57:00.282130win-unicode-console 0.5
2020-11-03 11:57:00.282130wincertstore 0.2
2020-11-03 11:57:00.282130zipp 3.4.0
2020-11-03 11:57:01.750979alabaster 0.7.11
2020-11-03 11:57:01.766604asn1crypto 0.24.0
2020-11-03 11:57:01.782234atomicwrites 1.2.1
2020-11-03 11:57:01.797856attrs 18.2.0
2020-11-03 11:57:01.797856backcall 0.1.0
2020-11-03 11:57:01.813481backports.os 0.1.1
2020-11-03 11:57:01.813481backports.shutil-get-terminal-size 1.0.0
2020-11-03 11:57:01.813481beautifulsoup4 4.6.3
2020-11-03 11:57:01.829107bitarray 0.8.3
2020-11-03 11:57:01.844734boto 2.49.0
2020-11-03 11:57:02.000996certifi 2020.11.8
2020-11-03 11:57:02.000996chardet 3.0.4
2020-11-03 11:57:02.032246click 6.7
2020-11-03 11:57:02.032246cloudpickle 0.5.5
2020-11-03 11:57:02.047872colorama 0.3.9
2020-11-03 11:57:02.047872comtypes 1.1.7
2020-11-03 11:57:02.094752constantly 15.1.0
2020-11-03 11:57:02.110380dask 0.19.1
2020-11-03 11:57:02.188520defusedxml 0.5.0
2020-11-03 11:57:02.204133docutils 0.14
2020-11-03 11:57:02.391653et-xmlfile 1.0.1
2020-11-03 11:57:02.391653fastcache 1.0.2
2020-11-03 11:57:02.407272glob2 0.6
2020-11-03 11:57:02.869805idna 2.7
2020-11-03 11:57:02.885429incremental 17.5.0
2020-11-03 11:57:02.932308lazy-object-proxy 1.3.1
2020-11-03 11:57:03.072943llvmlite 0.24.0
2020-11-03 11:57:03.088568locket 0.2.0
2020-11-03 11:57:03.104196MarkupSafe 1.0
2020-11-03 11:57:03.119821mkl-service 2.3.0
2020-11-03 11:57:03.135447mpmath 1.0.0
2020-11-03 11:57:03.166698msgpack 0.5.6
2020-11-03 11:57:03.182345numpy 1.19.2
2020-11-03 11:57:03.354212olefile 0.46
2020-11-03 11:57:03.369838parso 0.3.1
2020-11-03 11:57:03.401089pkginfo 1.4.2
2020-11-03 11:57:03.416714pluggy 0.7.1
2020-11-03 11:57:03.416714ply 3.11
2020-11-03 11:57:03.432355psutil 5.4.7
2020-11-03 11:57:03.447967py 1.6.0
2020-11-03 11:57:03.463593pyasn1 0.4.4
2020-11-03 11:57:03.494853pycparser 2.18
2020-11-03 11:57:03.572979pyflakes 2.0.0
2020-11-03 11:57:03.588603pytz 2018.5
2020-11-03 11:57:03.901121QtPy 1.5.0
2020-11-03 11:57:03.932374rope 0.11.0
2020-11-03 11:57:03.979266Send2Trash 1.5.0
2020-11-03 11:57:04.026131snowballstemmer 1.2.1
2020-11-03 11:57:04.041757sortedcontainers 2.0.5
2020-11-03 11:57:04.041757sphinxcontrib-applehelp 1.0.2
2020-11-03 11:57:04.041757sphinxcontrib-devhelp 1.0.2
2020-11-03 11:57:04.041757sphinxcontrib-htmlhelp 1.0.3
2020-11-03 11:57:04.041757sphinxcontrib-jsmath 1.0.1
2020-11-03 11:57:04.041757sphinxcontrib-qthelp 1.0.3
2020-11-03 11:57:04.041757sphinxcontrib-serializinghtml 1.1.4
2020-11-03 11:57:04.041757sphinxcontrib-websupport 1.1.0
2020-11-03 11:57:04.057384SQLAlchemy 1.2.11
2020-11-03 11:57:04.119886tblib 1.3.2
2020-11-03 11:57:04.135513testpath 0.3.1
2020-11-03 11:57:04.135513toolz 0.9.0
2020-11-03 11:57:04.151138tornado 5.1
2020-11-03 11:57:04.198017tqdm 4.26.0
2020-11-03 11:57:04.198017unicodecsv 0.14.1
2020-11-03 11:57:04.213643wcwidth 0.1.7
2020-11-03 11:57:04.213643webencodings 0.5.1
2020-11-03 11:57:04.229269Werkzeug 0.14.1
2020-11-03 11:57:04.276148wrapt 1.10.11
2020-11-03 11:57:04.276148xlrd 1.1.0
2020-11-03 11:57:04.307400XlsxWriter 1.1.0
2020-11-03 11:57:04.338652xlwt 1.3.0
2020-11-03 11:57:04.369909astroid 2.0.4
2020-11-03 11:57:04.369909zope.interface 4.5.0
2020-11-03 11:57:04.401155Automat 0.7.0
2020-11-03 11:57:04.416780Babel 2.6.0
2020-11-03 11:57:04.651174cffi 1.11.5
2020-11-03 11:57:04.666798cytoolz 0.9.0.1
2020-11-03 11:57:04.698050html5lib 1.0.1
2020-11-03 11:57:04.713675hyperlink 18.0.0
2020-11-03 11:57:04.729302jedi 0.12.1
2020-11-03 11:57:04.760554keyring 13.2.1
2020-11-03 11:57:04.807433menuinst 1.4.14
2020-11-03 11:57:04.807433more-itertools 4.3.0
2020-11-03 11:57:04.823058multipledispatch 0.6.0
2020-11-03 11:57:04.838883networkx 2.1
2020-11-03 11:57:05.026198nltk 3.3
2020-11-03 11:57:05.151205openpyxl 2.5.6
2020-11-03 11:57:05.229352packaging 17.1
2020-11-03 11:57:05.229352partd 0.3.8
2020-11-03 11:57:05.244962pathlib2 2.3.2
2020-11-03 11:57:05.244962pyasn1-modules 0.2.2
2020-11-03 11:57:05.276213python-dateutil 2.7.3
2020-11-03 11:57:05.291847pyzmq 17.1.2
2020-11-03 11:57:07.307599QtAwesome 0.4.4
2020-11-03 11:57:07.323224setuptools 40.2.0
2020-11-03 11:57:07.370103sortedcollections 1.0.1
2020-11-03 11:57:07.385728sympy 1.1.1
2020-11-03 11:57:07.838882traitlets 4.3.2
2020-11-03 11:57:07.854510xlwings 0.11.8
2020-11-03 11:57:07.870135zict 0.1.3
2020-11-03 11:57:07.901387bleach 2.1.4
2020-11-03 11:57:07.917015clyent 1.2.2
2020-11-03 11:57:07.932640cryptography 3.1.1
2020-11-03 11:57:07.963894Cython 0.28.5
2020-11-03 11:57:08.042021distributed 1.23.1
2020-11-03 11:57:08.120153gevent 1.3.6
2020-11-03 11:57:08.167029isort 4.3.4
2020-11-03 11:57:08.182659Jinja2 2.10
2020-11-03 11:57:08.182659jsonschema 2.6.0
2020-11-03 11:57:08.229534lxml 4.2.5
2020-11-03 11:57:08.260794nose 1.3.7
2020-11-03 11:57:08.276412Pillow 5.2.0
2020-11-03 11:57:08.323298Pygments 2.2.0
2020-11-03 11:57:08.573307pytest 3.8.0
2020-11-03 11:57:08.604559pywinpty 0.5.4
2020-11-03 11:57:08.620185wheel 0.31.1
2020-11-03 11:57:08.635819Flask 1.0.2
2020-11-03 11:57:08.635819jupyter-client 5.2.3
2020-11-03 11:57:08.667062navigator-updater 0.2.1
2020-11-03 11:57:08.698315nbformat 4.4.0
2020-11-03 11:57:08.838957prompt-toolkit 1.0.15
2020-11-03 11:57:08.870201pylint 2.1.1
2020-11-03 11:57:09.151470pyOpenSSL 18.0.0
2020-11-03 11:57:09.167097pytest-openfiles 0.3.0
2020-11-03 11:57:09.167097pytest-remotedata 0.3.0
2020-11-03 11:57:09.182722Flask-Cors 3.0.6
2020-11-03 11:57:09.182722terminado 0.8.1
2020-11-03 11:57:09.198348ipython 6.5.0
2020-11-03 11:57:09.307731nbconvert 5.4.0
2020-11-03 11:57:09.370237service-identity 17.0.0
2020-11-03 11:57:09.385863urllib3 1.23
2020-11-03 11:57:09.401487ipykernel 4.10.0
2020-11-03 11:57:10.906780requests 2.19.1
2020-11-03 11:57:10.922392Twisted 18.7.0
2020-11-03 11:57:11.328668anaconda-client 1.7.2
2020-11-03 11:57:11.406806jupyter-console 5.2.0
2020-11-03 11:57:11.406806prometheus-client 0.3.1
2020-11-03 11:57:11.422424qtconsole 4.4.1
2020-11-03 11:57:11.438050Sphinx 1.7.9
2020-11-03 11:57:11.563058spyder-kernels 0.2.6
2020-11-03 11:57:11.578684anaconda-navigator 1.9.2
2020-11-03 11:57:11.672443anaconda-project 0.8.2
2020-11-03 11:57:11.734958notebook 5.6.0
2020-11-03 11:57:12.031853numpydoc 0.8.0
2020-11-03 11:57:12.047479jupyterlab-launcher 0.13.1
2020-11-03 11:57:12.063091spyder 3.3.1
2020-11-03 11:57:12.266232ipywidgets 7.4.1
2020-11-03 11:57:12.266232widgetsnbextension 3.4.1
2020-11-03 11:57:12.297490jupyterlab 0.34.9
2020-11-03 11:57:12.344369bokeh 0.13.0
2020-11-03 11:57:12.563133Bottleneck 1.2.1
2020-11-03 11:57:12.563133conda 4.9.2
2020-11-03 11:57:12.703760conda-build 3.15.1
2020-11-03 11:57:12.735011datashape 0.5.4
2020-11-03 11:57:12.750637h5py 2.8.0
2020-11-03 11:57:12.781888imageio 2.4.1
2020-11-03 11:57:12.797515matplotlib 2.2.3
2020-11-03 11:57:12.922532mkl-fft 1.2.0
2020-11-03 11:57:12.922532mkl-random 1.1.0
2020-11-03 11:57:12.938150numba 0.39.0
2020-11-03 11:57:13.141289numexpr 2.7.1
2020-11-03 11:57:13.156924pandas 0.23.4
2020-11-03 11:57:13.391305pytest-arraydiff 0.2
2020-11-03 11:57:13.391305pytest-doctestplus 0.1.3
2020-11-03 11:57:13.406940PyWavelets 1.0.0
2020-11-03 11:57:13.422556scipy 1.5.2
2020-11-03 11:57:13.703828bkcharts 0.2
2020-11-03 11:57:13.735077patsy 0.5.0
2020-11-03 11:57:13.750703tables 3.4.4
2020-11-03 11:57:13.813221scikit-image 0.14.0
2020-11-03 11:57:13.969470scikit-learn 0.23.2
2020-11-03 11:57:14.125727astropy 3.0.4
2020-11-03 11:57:14.532006odo 0.5.1
2020-11-03 11:57:14.563257statsmodels 0.9.0
2020-11-03 11:57:14.907038blaze 0.11.3
2020-11-03 11:57:14.953907seaborn 0.9.0

后记

笔者稍微修改了一下上面的代码, 这样似乎更精确:

# -*- coding: UTF-8 -*-
# @author: caoyang
# @email: caoyang@163.sufe.edu.cn

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

class PipLogger(object):
	
	def __init__(self):		
		pass

	def logging_pip_install_packages(self):
		packages = []
		for package in get_installed_distributions():
			package_metadata_path = os.path.dirname(package._get_metadata_path_for_display('RECORD'))
			created_time = os.path.getctime(package_metadata_path)
			modified_time = os.path.getmtime(package_metadata_path)
			created_time = datetime.fromtimestamp(created_time)
			modified_time = datetime.fromtimestamp(modified_time)
			packages.append([created_time, modified_time, str(package)])
		print('|Index|createdTime|modifiedTime|package|')
		print('|----|----|----|----|')
		index = 0
		for created_time, modified_time, package_name_version in sorted(packages):
			index += 1
			print("|||||".format(index, created_time, modified_time, package_name_version))


if __name__ == '__main__':
	pip_logger = PipLogger()
	pip_logger.logging_pip_install_packages()

得出的结果就是这样的了, 一目了然, 非常满足强迫症:

anaconda自带安装的库

IndexcreatedTimemodifiedTimepackage
12020-11-03 11:57:00.2821302020-11-30 12:44:06.155658PyYAML 3.13
22020-11-03 11:57:00.2821302020-11-30 12:44:06.155658bitarray 0.8.3
32020-11-03 11:57:00.2821302020-11-30 12:44:06.155658boto 2.49.0
42020-11-03 11:57:00.2821302020-11-30 12:44:06.155658docutils 0.14
52020-11-03 11:57:00.2821302020-11-30 12:44:06.155658entrypoints 0.2.3
62020-11-03 11:57:00.2821302020-11-30 12:44:06.155658heapdict 1.0.0
72020-11-03 11:57:00.2821302020-11-30 12:44:06.155658imageio 2.4.1
82020-11-03 11:57:00.2821302020-11-30 12:44:06.155658ipython-genutils 0.2.0
92020-11-03 11:57:00.2821302020-11-30 12:44:06.155658llvmlite 0.24.0
102020-11-03 11:57:00.2821302020-11-30 12:44:06.155658locket 0.2.0
112020-11-03 11:57:00.2821302020-11-30 12:44:06.155658menuinst 1.4.14
122020-11-03 11:57:00.2821302020-11-30 12:44:06.155658mpmath 1.0.0
132020-11-03 11:57:00.2821302020-11-30 12:44:06.155658pycosat 0.6.3
142020-11-03 11:57:00.2821302020-11-30 12:44:06.155658pycrypto 2.6.1
152020-11-03 11:57:00.2821302020-11-30 12:44:06.155658pycurl 7.43.0.6
162020-11-03 11:57:00.2821302020-11-30 12:44:06.155658pyreadline 2.1
172020-11-03 11:57:00.2821302020-11-30 12:44:06.155658qtconsole 4.4.1
182020-11-03 11:57:00.2821302020-11-30 12:44:06.155658ruamel-yaml 0.15.46
192020-11-03 11:57:00.2821302020-11-30 12:44:06.155658snowballstemmer 1.2.1
202020-11-03 11:57:00.2821302020-11-30 12:44:06.155658spyder 3.3.1
212020-11-03 11:57:00.2821302020-11-30 12:44:06.155658sympy 1.1.1
222020-11-03 11:57:00.2821302020-11-30 12:44:06.155658terminado 0.8.1
232020-11-03 11:57:00.2821302020-11-30 12:44:06.155658win-inet-pton 1.0.1
242020-11-03 11:57:00.2821302020-11-30 12:44:06.155658wincertstore 0.2
252020-11-03 11:57:00.2821302020-11-30 12:44:06.155658wrapt 1.10.11
262020-11-03 11:57:01.7509792020-11-03 11:57:01.750979alabaster 0.7.11
272020-11-03 11:57:01.7666042020-11-03 11:57:01.766604appdirs 1.4.3
282020-11-03 11:57:01.7666042020-11-03 11:57:01.766604asn1crypto 0.24.0
292020-11-03 11:57:01.7822342020-11-03 11:57:01.782234atomicwrites 1.2.1
302020-11-03 11:57:01.7978562020-11-03 11:57:01.797856attrs 18.2.0
312020-11-03 11:57:01.7978562020-11-03 11:57:01.797856backcall 0.1.0
322020-11-03 11:57:01.8134812020-11-03 11:57:01.813481beautifulsoup4 4.6.3
332020-11-03 11:57:02.0009962020-11-03 11:57:02.000996chardet 3.0.4
342020-11-03 11:57:02.0166192020-11-03 11:57:02.032246click 6.7
352020-11-03 11:57:02.0322462020-11-03 11:57:02.032246cloudpickle 0.5.5
362020-11-03 11:57:02.0478722020-11-03 11:57:02.047872colorama 0.3.9
372020-11-03 11:57:02.0478722020-11-03 11:57:02.047872comtypes 1.1.7
382020-11-03 11:57:02.0947522020-11-03 11:57:02.094752constantly 15.1.0
392020-11-03 11:57:02.0947522020-11-03 11:57:02.110380contextlib2 0.5.5
402020-11-03 11:57:02.1103802020-11-03 11:57:02.110380dask 0.19.1
412020-11-03 11:57:02.1728802020-11-03 11:57:02.188520decorator 4.3.0
422020-11-03 11:57:02.1885202020-11-03 11:57:02.188520defusedxml 0.5.0
432020-11-03 11:57:02.3760192020-11-03 11:57:02.391653et-xmlfile 1.0.1
442020-11-03 11:57:02.3916532020-11-03 11:57:02.391653fastcache 1.0.2
452020-11-03 11:57:02.4072722020-11-03 11:57:02.407272filelock 3.0.8
462020-11-03 11:57:02.4072722020-11-03 11:57:02.407272glob2 0.6
472020-11-03 11:57:02.4072722020-11-03 11:57:02.407272greenlet 0.4.15
482020-11-03 11:57:02.8698052020-11-03 11:57:02.869805idna 2.7
492020-11-03 11:57:02.8854292020-11-03 11:57:02.885429imagesize 1.1.0
502020-11-03 11:57:02.8854292020-11-03 11:57:02.885429incremental 17.5.0
512020-11-03 11:57:02.9010552020-11-03 11:57:02.916683itsdangerous 0.24
522020-11-03 11:57:02.9166832020-11-03 11:57:02.916683jdcal 1.4
532020-11-03 11:57:02.9166832020-11-03 11:57:02.916683kiwisolver 1.0.1
542020-11-03 11:57:02.9323082020-11-03 11:57:02.932308lazy-object-proxy 1.3.1
552020-11-03 11:57:03.1041962020-11-03 11:57:03.104196MarkupSafe 1.0
562020-11-03 11:57:03.1041962020-11-03 11:57:03.104196mccabe 0.6.1
572020-11-03 11:57:03.1198212020-11-03 11:57:03.119821mistune 0.8.3
582020-11-03 11:57:03.1666982020-11-03 11:57:03.166698msgpack 0.5.6
592020-11-03 11:57:03.3542122020-11-03 11:57:03.354212olefile 0.46
602020-11-03 11:57:03.3542122020-11-03 11:57:03.354212pandocfilters 1.4.2
612020-11-03 11:57:03.3698382020-11-03 11:57:03.369838parso 0.3.1
622020-11-03 11:57:03.3854712020-11-03 11:57:03.385471path.py 11.1.0
632020-11-03 11:57:03.3854712020-11-03 11:57:03.385471pep8 1.7.1
642020-11-03 11:57:03.4010892020-11-03 11:57:03.401089pickleshare 0.7.4
652020-11-03 11:57:03.4010892020-11-03 11:57:03.401089pkginfo 1.4.2
662020-11-03 11:57:03.4167142020-11-03 11:57:03.416714pluggy 0.7.1
672020-11-03 11:57:03.4167142020-11-03 11:57:03.416714ply 3.11
682020-11-03 11:57:03.4323552020-11-03 11:57:03.432355psutil 5.4.7
692020-11-03 11:57:03.4479672020-11-03 11:57:03.447967py 1.6.0
702020-11-03 11:57:03.4635932020-11-03 11:57:03.463593pyasn1 0.4.4
712020-11-03 11:57:03.4792182020-11-03 11:57:03.494853pycodestyle 2.4.0
722020-11-03 11:57:03.4948532020-11-03 11:57:03.494853pycparser 2.18
732020-11-03 11:57:03.5729792020-11-03 11:57:03.572979pyflakes 2.0.0
742020-11-03 11:57:03.5729792020-11-03 11:57:03.572979pyodbc 4.0.24
752020-11-03 11:57:03.5886032020-11-03 11:57:03.588603pyparsing 2.2.0
762020-11-03 11:57:03.5886032020-11-03 11:57:03.588603pytz 2018.5
772020-11-03 11:57:03.7448612020-11-03 11:57:03.744861pywin32 223
782020-11-03 11:57:03.9011212020-11-03 11:57:03.901121QtPy 1.5.0
792020-11-03 11:57:03.9323742020-11-03 11:57:03.932374rope 0.11.0
802020-11-03 11:57:03.9792662020-11-03 11:57:03.979266Send2Trash 1.5.0
812020-11-03 11:57:03.9948862020-11-03 11:57:03.994886simplegeneric 0.8.1
822020-11-03 11:57:04.0105132020-11-03 11:57:04.010513six 1.11.0
832020-11-03 11:57:04.0417572020-11-03 11:57:04.041757sortedcontainers 2.0.5
842020-11-03 11:57:04.0417572020-11-03 11:57:04.057384SQLAlchemy 1.2.11
852020-11-03 11:57:04.1198862020-11-03 11:57:04.119886tblib 1.3.2
862020-11-03 11:57:04.1355132020-11-03 11:57:04.135513testpath 0.3.1
872020-11-03 11:57:04.1355132020-11-03 11:57:04.135513toolz 0.9.0
882020-11-03 11:57:04.1511382020-11-03 11:57:04.151138tornado 5.1
892020-11-03 11:57:04.1980172020-11-03 11:57:04.198017tqdm 4.26.0
902020-11-03 11:57:04.1980172020-11-03 11:57:04.198017unicodecsv 0.14.1
912020-11-03 11:57:04.2136432020-11-03 11:57:04.213643wcwidth 0.1.7
922020-11-03 11:57:04.2136432020-11-03 11:57:04.213643webencodings 0.5.1
932020-11-03 11:57:04.2292692020-11-03 11:57:04.229269Werkzeug 0.14.1
942020-11-03 11:57:04.2607322020-11-03 11:57:04.260732win-unicode-console 0.5
952020-11-03 11:57:04.2761482020-11-03 11:57:04.276148xlrd 1.1.0
962020-11-03 11:57:04.3074002020-11-03 11:57:04.307400XlsxWriter 1.1.0
972020-11-03 11:57:04.3230252020-11-03 11:57:04.338652xlwt 1.3.0
982020-11-03 11:57:04.3699092020-11-03 11:57:04.369909astroid 2.0.4
992020-11-03 11:57:04.4011552020-11-03 11:57:04.401155Automat 0.7.0
1002020-11-03 11:57:04.4167802020-11-03 11:57:04.416780Babel 2.6.0
1012020-11-03 11:57:04.6355452020-11-03 11:57:04.635545backports.shutil-get-terminal-size 1.0.0
1022020-11-03 11:57:04.6511742020-11-03 11:57:04.651174cffi 1.11.5
1032020-11-03 11:57:04.6667982020-11-03 11:57:04.666798cycler 0.10.0
1042020-11-03 11:57:04.6667982020-11-03 11:57:04.666798cytoolz 0.9.0.1
1052020-11-03 11:57:04.6980502020-11-03 11:57:04.698050html5lib 1.0.1
1062020-11-03 11:57:04.7136752020-11-03 11:57:04.713675hyperlink 18.0.0
1072020-11-03 11:57:04.7293022020-11-03 11:57:04.729302jedi 0.12.1
1082020-11-03 11:57:04.7605542020-11-03 11:57:04.760554keyring 13.2.1
1092020-11-03 11:57:04.8074332020-11-03 11:57:04.807433more-itertools 4.3.0
1102020-11-03 11:57:04.8230582020-11-03 11:57:04.823058multipledispatch 0.6.0
1112020-11-03 11:57:04.8230582020-11-03 11:57:04.838883networkx 2.1
1122020-11-03 11:57:05.0261982020-11-03 11:57:05.026198nltk 3.3
1132020-11-03 11:57:05.1512052020-11-03 11:57:05.151205openpyxl 2.5.6
1142020-11-03 11:57:05.2293522020-11-03 11:57:05.229352packaging 17.1
1152020-11-03 11:57:05.2293522020-11-03 11:57:05.229352partd 0.3.8
1162020-11-03 11:57:05.2449622020-11-03 11:57:05.244962pathlib2 2.3.2
1172020-11-03 11:57:05.2449622020-11-03 11:57:05.244962pyasn1-modules 0.2.2
1182020-11-03 11:57:05.2605952020-11-03 11:57:05.260595PySocks 1.6.8
1192020-11-03 11:57:05.2762132020-11-03 11:57:05.276213python-dateutil 2.7.3
1202020-11-03 11:57:05.2918472020-11-03 11:57:05.291847pyzmq 17.1.2
1212020-11-03 11:57:07.3075992020-11-03 11:57:07.307599QtAwesome 0.4.4
1222020-11-03 11:57:07.3232242020-11-03 11:57:07.323224setuptools 40.2.0
1232020-11-03 11:57:07.3544752020-11-03 11:57:07.354475singledispatch 3.4.0.3
1242020-11-03 11:57:07.3701032020-11-03 11:57:07.370103sortedcollections 1.0.1
1252020-11-03 11:57:07.3701032020-11-03 11:57:07.385728sphinxcontrib-websupport 1.1.0
1262020-11-03 11:57:07.8388822020-11-03 11:57:07.838882traitlets 4.3.2
1272020-11-03 11:57:07.8545102020-11-03 11:57:07.854510xlwings 0.11.8
1282020-11-03 11:57:07.8701352020-11-03 11:57:07.870135zict 0.1.3
1292020-11-03 11:57:07.8857612020-11-03 11:57:07.885761zope.interface 4.5.0
1302020-11-03 11:57:07.9013872020-11-03 11:57:07.901387bleach 2.1.4
1312020-11-03 11:57:07.9170152020-11-03 11:57:07.917015clyent 1.2.2
1322020-11-03 11:57:07.9638942020-11-03 11:57:07.963894Cython 0.28.5
1332020-11-03 11:57:08.0420212020-11-03 11:57:08.042021distributed 1.23.1
1342020-11-03 11:57:08.1201532020-11-03 11:57:08.120153gevent 1.3.6
1352020-11-03 11:57:08.1670292020-11-03 11:57:08.167029Jinja2 2.10
1362020-11-03 11:57:08.1670292020-11-03 11:57:08.167029isort 4.3.4
1372020-11-03 11:57:08.1826592020-11-03 11:57:08.182659jsonschema 2.6.0
1382020-11-03 11:57:08.2139172020-11-03 11:57:08.213917jupyter-core 4.4.0
1392020-11-03 11:57:08.2295342020-11-03 11:57:08.229534lxml 4.2.5
1402020-11-03 11:57:08.2451612020-11-03 11:57:08.260794nose 1.3.7
1412020-11-03 11:57:08.3076652020-11-03 11:57:08.307665Pillow 5.2.0
1422020-11-03 11:57:08.3232982020-11-03 11:57:08.323298Pygments 2.2.0
1432020-11-03 11:57:08.6045592020-11-03 11:57:08.604559pytest 3.8.0
1442020-11-03 11:57:08.6045592020-11-03 11:57:08.604559pywinpty 0.5.4
1452020-11-03 11:57:08.6201852020-11-03 11:57:08.620185wheel 0.31.1
1462020-11-03 11:57:08.6201852020-11-03 11:57:08.635819Flask 1.0.2
1472020-11-03 11:57:08.6358192020-11-03 11:57:08.635819jupyter-client 5.2.3
1482020-11-03 11:57:08.6670622020-11-03 11:57:08.667062navigator-updater 0.2.1
1492020-11-03 11:57:08.6983152020-11-03 11:57:08.698315nbformat 4.4.0
1502020-11-03 11:57:08.8233232020-11-03 11:57:08.838957prompt-toolkit 1.0.15
1512020-11-03 11:57:08.8702012020-11-03 11:57:08.870201pylint 2.1.1
1522020-11-03 11:57:09.1514702020-11-03 11:57:09.151470pyOpenSSL 18.0.0
1532020-11-03 11:57:09.1670972020-11-03 11:57:09.167097pytest-openfiles 0.3.0
1542020-11-03 11:57:09.1670972020-11-03 11:57:09.167097pytest-remotedata 0.3.0
1552020-11-03 11:57:09.1827222020-11-03 11:57:09.182722Flask-Cors 3.0.6
1562020-11-03 11:57:09.2921042020-11-03 11:57:09.292104ipython 6.5.0
1572020-11-03 11:57:09.3077312020-11-03 11:57:09.307731nbconvert 5.4.0
1582020-11-03 11:57:09.3702372020-11-03 11:57:09.370237service-identity 17.0.0
1592020-11-03 11:57:09.3858632020-11-03 11:57:09.385863urllib3 1.23
1602020-11-03 11:57:09.4014872020-11-03 11:57:09.401487ipykernel 4.10.0
1612020-11-03 11:57:10.9067802020-11-03 11:57:10.906780requests 2.19.1
1622020-11-03 11:57:10.9223922020-11-03 11:57:10.922392Twisted 18.7.0
1632020-11-03 11:57:11.3286682020-11-03 11:57:11.328668anaconda-client 1.7.2
1642020-11-03 11:57:11.3911732020-11-03 11:57:11.406806jupyter-console 5.2.0
1652020-11-03 11:57:11.4068062020-11-03 11:57:11.406806prometheus-client 0.3.1
1662020-11-03 11:57:11.4380502020-11-03 11:57:11.438050Sphinx 1.7.9
1672020-11-03 11:57:11.5630582020-11-03 11:57:11.563058spyder-kernels 0.2.6
1682020-11-03 11:57:11.5786842020-11-03 11:57:11.578684anaconda-navigator 1.9.2
1692020-11-03 11:57:11.6724432020-11-03 11:57:11.672443anaconda-project 0.8.2
1702020-11-03 11:57:11.7349582020-11-03 11:57:11.734958notebook 5.6.0
1712020-11-03 11:57:12.0318532020-11-03 11:57:12.031853numpydoc 0.8.0
1722020-11-03 11:57:12.0474792020-11-03 11:57:12.047479jupyterlab-launcher 0.13.1
1732020-11-03 11:57:12.2506042020-11-03 11:57:12.266232widgetsnbextension 3.4.1
1742020-11-03 11:57:12.2662322020-11-03 11:57:12.266232ipywidgets 7.4.1
1752020-11-03 11:57:12.2818562020-11-03 11:57:12.297490jupyterlab 0.34.9
1762020-11-03 11:57:12.3443692020-11-03 11:57:12.344369bokeh 0.13.0
1772020-11-03 11:57:12.3443692020-11-03 11:57:12.344369jupyter 1.0.0
1782020-11-03 11:57:12.5474982020-11-03 11:57:12.563133Bottleneck 1.2.1
1792020-11-03 11:57:12.6881332020-11-03 11:57:12.703760conda-build 3.15.1
1802020-11-03 11:57:12.7350112020-11-03 11:57:12.735011datashape 0.5.4
1812020-11-03 11:57:12.7506372020-11-03 11:57:12.750637h5py 2.8.0
1822020-11-03 11:57:12.7975152020-11-03 11:57:12.797515matplotlib 2.2.3
1832020-11-03 11:57:12.9381502020-11-03 11:57:12.938150numba 0.39.0
1842020-11-03 11:57:13.1569242020-11-03 11:57:13.156924pandas 0.23.4
1852020-11-03 11:57:13.3913052020-11-03 11:57:13.391305pytest-arraydiff 0.2
1862020-11-03 11:57:13.3913052020-11-03 11:57:13.391305pytest-doctestplus 0.1.3
1872020-11-03 11:57:13.4069402020-11-03 11:57:13.406940PyWavelets 1.0.0
1882020-11-03 11:57:13.7038282020-11-03 11:57:13.703828bkcharts 0.2
1892020-11-03 11:57:13.7350772020-11-03 11:57:13.735077patsy 0.5.0
1902020-11-03 11:57:13.7507032020-11-03 11:57:13.781955tables 3.4.4
1912020-11-03 11:57:13.8132212020-11-03 11:57:13.813221pytest-astropy 0.4.0
1922020-11-03 11:57:13.8132212020-11-03 11:57:13.813221scikit-image 0.14.0
1932020-11-03 11:57:14.1257272020-11-03 11:57:14.125727astropy 3.0.4
1942020-11-03 11:57:14.5163872020-11-03 11:57:14.532006odo 0.5.1
1952020-11-03 11:57:14.5632572020-11-03 11:57:14.563257statsmodels 0.9.0
1962020-11-03 11:57:14.9070382020-11-03 11:57:14.907038blaze 0.11.3
1972020-11-03 11:57:14.9539072020-11-03 11:57:14.953907seaborn 0.9.0
1982020-11-03 14:43:00.5433072020-11-03 14:43:01.075886selenium 3.141.0
1992020-11-03 15:31:08.3526922020-11-03 15:31:08.386588opencv-python 4.4.0.46

pip list 常规日志

IndexcreatedTimemodifiedTimepackagenote
2002020-11-15 13:27:43.7354522020-11-15 13:27:43.735452conda-package-handling 1.7.2与安装torch相关;
2012020-11-15 13:27:43.7510652020-11-15 13:27:43.766689mkl-service 2.3.0与安装torch相关;
2022020-11-15 13:27:48.8482692020-11-15 13:27:48.848269cryptography 3.1.1与安装torch相关;
2032020-11-15 13:27:49.1608152020-11-19 15:24:03.165432conda 4.9.2与安装torch相关;
2042020-11-15 13:27:49.3795712020-11-15 13:27:49.379571mkl-fft 1.2.0与安装

以上是关于日常查看Python库的本地安装信息及pip库的使用方法(补tensorflow2.3.0所有依赖whl)的主要内容,如果未能解决你的问题,请参考以下文章

python查看安装的第三方库的版本

查看python第三方库的位置and-python自带的库pip安装的库

python3安装pandas执行pip3 install pandas命令后卡住不动的问题及安装scipysklearn库的numpy.distutils.system_info.NotFound(

Python库的优雅安装及PyCharm虚拟环境配置

Python库的安装

使用pip命令和本地whl安装Python扩展库的方法(以scipy-1.5.4为例,附scipy-1.5.4高速下载链接)

(c)2006-2024 SYSTEM All Rights Reserved IT常识