如何獲取本地安裝 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
...

如果你使用的是 pip 版本 >= 1.3,你還可以使用 pip list。例如:

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

更新於: 2019 年 9 月 30 日

已獲 3K+ 次瀏覽

開啟你的職業生涯

完成課程,獲得認證

開始
廣告
© . All rights reserved.