2024-04-19 01:24:21 发布
网友
Python中是否有列出所有已安装的包及其版本的方法?
我知道我可以进入python/Lib/site-packages查看存在哪些文件和目录,但我觉得这很尴尬。我要找的是类似于npm list的东西,即npm-ls。
python/Lib/site-packages
npm list
如果您安装了pip,并且希望查看安装工具安装了哪些软件包,您可以简单地调用以下命令:
pip freeze
它还将包括已安装软件包的版本号。
更新
pip已更新,通过调用以下命令还可以生成与pip freeze相同的输出:
pip list
注意
来自pip list的输出格式不同,因此如果您有解析freeze的输出(可能是为了获取版本号)并希望将脚本更改为调用list的shell脚本,则需要更改解析代码。
freeze
list
如果您想获得有关已安装的python发行版的信息,并且不想使用cmd控制台或终端,而是通过python代码,则可以使用以下代码(使用python 3.4测试):
import pip #needed to use the pip functions for i in pip.get_installed_distributions(local_only=True): print(i)
函数调用pip.get_installed_distributions(local_only=True)返回一个iterable,由于for循环和print函数,iterable中包含的元素由新行字符(\n)分隔出来。 结果将(取决于您安装的发行版)如下所示:
pip.get_installed_distributions(local_only=True)
\n
cycler 0.9.0 decorator 4.0.4 ipykernel 4.1.0 ipython 4.0.0 ipython-genutils 0.1.0 ipywidgets 4.0.3 Jinja2 2.8 jsonschema 2.5.1 jupyter 1.0.0 jupyter-client 4.1.1 #... and so on...
help('modules')应该为你做。
help('modules')
在伊普顿:
In [1]: import #import press-TAB Display all 631 possibilities? (y or n) ANSI audiodev markupbase AptUrl audioop markupsafe ArgImagePlugin avahi marshal BaseHTTPServer axi math Bastion base64 md5 BdfFontFile bdb mhlib BmpImagePlugin binascii mimetools BufrStubImagePlugin binhex mimetypes CDDB bisect mimify CDROM bonobo mmap CGIHTTPServer brlapi mmkeys Canvas bsddb modulefinder CommandNotFound butterfly multifile ConfigParser bz2 multiprocessing ContainerIO cPickle musicbrainz2 Cookie cProfile mutagen Crypto cStringIO mutex CurImagePlugin cairo mx DLFCN calendar netrc DcxImagePlugin cdrom new Dialog cgi nis DiscID cgitb nntplib DistUpgrade checkbox ntpath
如果您安装了pip,并且希望查看安装工具安装了哪些软件包,您可以简单地调用以下命令:
它还将包括已安装软件包的版本号。
更新
pip已更新,通过调用以下命令还可以生成与
pip freeze
相同的输出:注意
来自
pip list
的输出格式不同,因此如果您有解析freeze
的输出(可能是为了获取版本号)并希望将脚本更改为调用list
的shell脚本,则需要更改解析代码。如果您想获得有关已安装的python发行版的信息,并且不想使用cmd控制台或终端,而是通过python代码,则可以使用以下代码(使用python 3.4测试):
函数调用
pip.get_installed_distributions(local_only=True)
返回一个iterable,由于for循环和print函数,iterable中包含的元素由新行字符(\n
)分隔出来。 结果将(取决于您安装的发行版)如下所示:help('modules')
应该为你做。在伊普顿:
相关问题 更多 >
编程相关推荐