如何在Python中列出所有已安装的软件包及其版本? [英] How to list all installed packages and their versions in Python?

查看:442
本文介绍了如何在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屋!

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