問題描述
我想知道是否有任何可靠且一致的方法來獲取 Python 包的導入名稱"/命名空間.例如;
I wonder if is there any reliable and consistant way to get a Python package's "import name" / namespace. For example;
包;django 干草堆
進口名稱;干草堆
Package; django-haystack
Import name; haystack
或
包;ipython
進口名稱;IPython
Package; ipython
Import name; IPython
到目前為止,我知道,PyPi 不存儲我使用 PyPiXmlRpc 檢查過的信息.
So far I know, PyPi doesn't store that information that I've checked with PyPiXmlRpc.
我還嘗試自動下載包、解壓縮并挖掘 .egg-info,但有些包根本沒有那個文件夾.
I also tried to automate to download the package, extract it and dig the .egg-info but some packages doesn't have that folder at all.
任何幫助將不勝感激,并將用于一個禮貌的小工具:)
Any help will be appreciated and will be used for a good-manner gadget :)
推薦答案
注意這里所說的包不是包,而是發行版.一個發行版可以包含零個或多個模塊或包.這意味著分發包與包之間沒有一對一的映射.
Note that what you call a package here is not a package but a distribution. A distribution can contain zero or more modules or packages. That means there is no one-to-one mapping of distributions to packages.
我不確定是否有辦法檢測發行版將安裝哪些模塊和包,而不是實際安裝它并檢查新添加的包、模塊和 pth 文件的文件系統更改.
I'm not sure there is a way to detect what modules and packages will be installed by a distribution, other than actually installing it and introspect filesystem changes for newly added packages, modules and pth files.
這篇關于如何找到“進口名稱"Python中的任何包?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!