在Python中有没有一种方法可以列出所有已安装的软件包及其版本?
我知道我可以进入python/Lib/site-packages
并查看存在哪些文件和目录,但我发现这非常尴尬。我正在寻找的是类似于npm list
的东西,即npm-ls。
发布于 2012-10-18 01:31:21
help('modules')
应该为你做这件事。
在IPython中:
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
发布于 2015-11-01 06:42:21
如果您想获取有关已安装的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)
函数调用返回一个迭代器,由于使用了for循环和print函数,包含在迭代器中的元素被换行符(\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...
发布于 2016-02-24 20:22:48
从命令行
python -c help('modules')
可用于查看所有模块,并可用于特定模块
python -c help('os')
对于Linux,下面的代码将有效
python -c "help('os')"
https://stackoverflow.com/questions/12939975
复制相似问题