How to list the names of PyPI packages corresponding to imports in a script?

谁说胖子不能爱 提交于 2019-12-18 17:00:03

问题


Is there a way to list the PyPi package names which correspond to modules being imported in a script?

For instance to import the module scapy3k (this is its name) I need to use

import scapy.all

but the actual package to install is scapy-python3. The latter is what I am looking to extract from what I will find in the import statement (I do not care about its name - scapy3k in that case).

There are other examples (which escape me right now) of packages which have a pip install name completely different from what is being used in the import afterwards.


回答1:


The name listed on pypi is the name defined in the distribution's setup.py / setup.cfg file. There is no requirement that this name relates to the name of the package that will be installed. So there is no 100% reliable way to obtain the name of a distribution on pypi, given only the name of the package that it installs (the use case identified in the OP's comment).



来源:https://stackoverflow.com/questions/36622480/how-to-list-the-names-of-pypi-packages-corresponding-to-imports-in-a-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!