如何在 Python 中列出所有已安装的软件包及其版本? [英] How to list all installed packages and their versions in Python?
问题描述
Python 有没有办法列出所有已安装的软件包及其版本?
Is there a way in Python to list all installed packages and their versions?
我知道我可以进入 python/Lib/site-packages
并查看存在哪些文件和目录,但我觉得这很尴尬.我正在寻找类似于 npm list
的东西,即 npm-ls.
I know I can go inside python/Lib/site-packages
and see what files and directories exist, but I find this very awkward. What I'm looking for something that is similar to npm list
i.e. npm-ls.
推荐答案
如果你有 pip install 并且你想看看你的安装工具安装了哪些包,你可以简单地调用这个:
If you have pip install and you want to see what packages have been installed with your installer tools you can simply call this:
pip freeze
它还包括已安装软件包的版本号.
It will also include version numbers for the installed packages.
更新
pip 已更新为也产生与 pip freeze
相同的输出,调用:
pip has been updated to also produce the same output as pip freeze
by calling:
pip list
注意
pip list
的输出格式不同,所以如果你有一些 shell 脚本来解析 freeze
的输出(也许是为了获取版本号)并且想要更改脚本以调用 list
,您需要更改解析代码.
The output from pip list
is formatted differently, so if you have some shell script that parses the output (maybe to grab the version number) of freeze
and want to change your script to call list
, you'll need to change your parsing code.
这篇关于如何在 Python 中列出所有已安装的软件包及其版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!