4

In cases where we have python code, but no instructions about which packages to install via pip before running the code, and we run it:

import inception5h

ERROR: Could not find a version that satisfies the requirement inception5h (from versions: none)
ERROR: No matching distribution found for inception5h

Is it safe to guess - i.e. try something like pip install inception5h or pip install inception?

I assume that in absence of specific instructions about which package to install, we are simply guessing, since (I think), any package could theoretically have modules of any name (that is, there could be numerous packages with a module named inception5h).

Is this understanding correct? And are there any clever ways of figuring out which package needs to be installed, preferably without guessing?

stevec
  • 41,291
  • 27
  • 223
  • 311
  • 2
    Sorry for the noise with closing/reopening. Still, check out https://stackoverflow.com/q/7184375/2650249 since its accepted answer should answer yours. – hoefling Jul 10 '20 at 14:40
  • 1
    Do you, by chance have a working installation of this package somewhere (maybe in a different virtual environment or on a different computer)? – sinoroc Jul 10 '20 at 17:16
  • 1
    @sinoroc thanks a lot for the help. Actually, I messed up - buried in [this](https://hackernoon.com/deep-dream-with-tensorflow-a-practical-guide-to-build-your-first-deep-dream-experience-f91df601f479) long article is a line that says inception5h is a file (not a package as I had assumed). I will replace the example if there is a better one? – stevec Jul 10 '20 at 17:20

3 Answers3

7

Update May 2021

This should nowadays be relatively straightforward with importlib_metadata.packages_distributions().

See the documentation here: stdlib or external.


Original answer

That I know of, there is no straightforward (non-guess) way to deduce the name of a (PyPI) distribution package name when all you have is the name of an import package (or module). As explained in the this answer for example (linked by @hoefling in the comments to your question).

There is obviously the convention of having in each distribution package 1 top-level importable package (or module) with the same name.

So, for example pip install requests allows you to write the Python code import requests.

But it is just a convention and obviously there are outliers:

  • Some have more than 1 top-level importable package, for example setuptools:
    • pip import setuptools
    • import setuptools and import pkg_resources
  • Some have different names entirely, for example the project PyYAML:
    • pip install pyyaml
    • import yaml

In such a case, I think I would probably try to look up the name of the import package in a web search engine and hope to find some results leading to the name of the distribution package.

wim
  • 338,267
  • 99
  • 616
  • 750
sinoroc
  • 18,409
  • 2
  • 39
  • 70
0

You can always check that what library you are installing is correct or wrong on www.pypi.org all the python modules are available here.

Gaurav Kulkarni
  • 190
  • 1
  • 14
-1

Visit https://pypi.org/(Python Packaging Index) for getting the command for installing the module. In your case it's pip install inception In the future for documentation for installing any module in Python, search the module in pypi and copy the installation command

griffin_cosgrove
  • 419
  • 8
  • 16
  • I tried what you suggested (`pip install inception`) but still see `import inception5h` giving `Traceback (most recent call last): File "", line 1, in ModuleNotFoundError: No module named 'inception5h'` – stevec Jul 10 '20 at 14:03
  • 2
    Doesn't seem to answer the question. – sinoroc Jul 10 '20 at 17:03