如何获取本地安装的Python模块列表?

有多种方法来获取本地安装的Python模块列表。最简单的方法是使用Python Shell,例如,

>>> help('modules')
Please wait a moment while I gather a list of all available modules...
BaseHTTPServer      brain_nose          markupbase          stat
Bastion             brain_numpy         marshal             statvfs
CGIHTTPServer       brain_pkg_resources math                string
Canvas              brain_pytest        matplotlib          stringold
...
...

如果要获取终端中已安装模块的列表,可以使用Python软件包管理器pip。例如,

$ pip freeze

您将获得输出:

asn1crypto==0.22.0
astroid==1.5.2
attrs==16.3.0
Automat==0.5.0
backports.functools-lru-cache==1.3
cffi==1.10.0
...

如果您的点子版本> = 1.3,也可以使用点子列表。例如,

$ pip list
asn1crypto (0.22.0)
astroid (1.5.2)
attrs (16.3.0)
Automat (0.5.0)
backports.functools-lru-cache (1.3)
...
...