如何在脚本中列出与导入相对应的PyPI软件包的名称

如何在脚本中列出与导入相对应的PyPI软件包的名称

本文介绍了如何在脚本中列出与导入相对应的PyPI软件包的名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以列出与脚本中导入的模块相对应的 PyPi软件包名称?

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

例如要导入模块 scapy3k (这是它的名称),我需要使用

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

import scapy.all

,但是要安装的实际软件包是scapy-python3.后者是我希望从import语句中找到的内容中提取的内容(在这种情况下,我并不关心它的名称-scapy3k).

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).

还有其他一些示例(现在让我逃脱了),这些软件包的pip install名称与之后的import名称完全不同.

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.

推荐答案

在pypi上列出的名称是名称.不需要此名称与将要安装的软件包的名称有关.因此,仅给出要安装的软件包的名称(OP注释中确定的用例),就没有100%可靠的方式来获取pypi上的发行版的名称.

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).

这篇关于如何在脚本中列出与导入相对应的PyPI软件包的名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 15:42