1

I am trying to programatically find information (such as version number) about imported modules using:

pip show *insert package name*

In Python this looks like:

subprocess.check_output([sys.executable, '-m', 'pip', 'show', *packagename*]).decode("utf-8")

However, the name that is passed as argument to PIP to find information is not always the same as the name used to import the module.

Is there a way to find the name that PIP uses, from the name you use to import the module?

Sam Drew
  • 13
  • 3
  • You can [find the way](https://stackoverflow.com/questions/19086030/can-pip-or-setuptools-distribute-etc-list-the-license-used-by-each-install/55753985#55753985) from [`pkg_resources.working_set`](https://setuptools.readthedocs.io/en/latest/pkg_resources.html#workingset-objects) you get a list of involved `module_path` and get allvalid `name` from [`pkgutil.iter_modules(list_of_modules_paths)`](https://docs.python.org/3/library/pkgutil.html#pkgutil.iter_modules). Then you check if `os.path.join(, )` is a directory (equivalent to `ispkg`) or it is a file with extension `.py`. – raratiru Apr 21 '19 at 22:30

0 Answers0