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

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

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