如何找到“导入名称" Python中的任何软件包? [英] How to find "import name" of any package in Python?
问题描述
我想知道是否有任何可靠且一致的方法来获取Python包的导入名称"/名称空间.例如;
I wonder if is there any reliable and consistant way to get a Python package's "import name" / namespace. For example;
包装; django-haystack
导入名称;干草堆
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 modules 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中的任何软件包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!