Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 895
WoJ Avatar asked Apr 14 '16 12:04

WoJ


1 Answers

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

like image 51
snakecharmerb Avatar answered Oct 12 '22 09:10

snakecharmerb