如何在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安装,并且想查看安装程序工具已安装了哪些软件包,则可以简单地称呼它:
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屋!