[Python] 使用 johnnydep 列出某套件的所有相依套件
最近遇到了 Python 模組相依性 (dependency) 的問題,
起因是我們的建置環境沒有對外網路連線,
因此不能直接使用 pip/yum 去 Internet 抓套件,
都得先在別台機器抓好套件的 tgz 或 zip 檔,再傳過去安裝。
但有時候,一個 Python 套件可能又相依於其他套件,
要將所有的相依性都找出來,有點麻煩…
查了一下,有人推薦他自己寫的 johnnydep 套件,
可以用來達成這個任務~
首先用 pip 安裝 johnnydep:
pip install johnnydep
接著,執行 johnnydep <套件名稱> 就可以了~
像我想查看 generateDS 這個套件的相依性,
就打 johnnydep generateDS,就可以查詢到:
testuser@localhost ~ $ johnnydep generateDS 2020-09-18 08:45:20 [info ] init johnnydist [johnnydep.lib] dist=generateDS parent=None 2020-09-18 08:45:23 [info ] init johnnydist [johnnydep.lib] dist=u'lxml' parent=generateDS 2020-09-18 08:45:27 [info ] init johnnydist [johnnydep.lib] dist=u'requests>=2.21.0' parent=generateDS 2020-09-18 08:45:29 [info ] init johnnydist [johnnydep.lib] dist=u'six' parent=generateDS 2020-09-18 08:45:30 [info ] init johnnydist [johnnydep.lib] dist=u'certifi>=2017.4.17' parent=requests>=2.21.0 2020-09-18 08:45:32 [info ] init johnnydist [johnnydep.lib] dist=u'chardet<4,>=3.0.2' parent=requests>=2.21.0 2020-09-18 08:45:33 [info ] init johnnydist [johnnydep.lib] dist=u'idna<3,>=2.5' parent=requests>=2.21.0 2020-09-18 08:45:35 [info ] init johnnydist [johnnydep.lib] dist=u'urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1' parent=requests>=2.21.0 name summary ----------------------------------------------- ------------------------------------------------------------------------------------------------ generateDS Generate Python data structures and XML parser from Xschema ├── lxml Powerful and Pythonic XML processing library combining libxml2/libxslt with the ElementTree API. ├── requests>=2.21.0 Python HTTP for Humans. │ ├── certifi>=2017.4.17 Python package for providing Mozilla's CA Bundle. │ ├── chardet<4,>=3.0.2 Universal encoding detector for Python 2 and 3 │ ├── idna<3,>=2.5 Internationalized Domain Names in Applications (IDNA) │ └── urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 HTTP library with thread-safe connection pooling, file post, and more. └── six Python 2 and 3 compatibility utilities
可以看到上面的樹狀結構很清楚的展示出第 1 層、第 2 層… 等等的相依關係,
像是 generateDS 會直接用到 lxml, requests, six 這三個套件,
而像 requests 又用到 certifi, chardet, idna, urllib3 等等套件。
同時,所需套件的版本限制也都有列出來,算是相當清楚方便,
很適合用在找出所有相依套件、並預先下載的情境中喔~
參考資料:python – Is there a way to list pip dependencies/requirements? – Stack Overflow
(本頁面已被瀏覽過 955 次)