How to list the names of PyPI packages corresponding to imports in a script?
Question: 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`](https://github.com/phaethon/scapy) (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.


Answer: The name listed on pypi is the
[name](https://packaging.python.org/en/latest/distributing/#setup-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).

