How to get the distribution name of an imported package in Python3.10+
I have multiple distributions that each provide a Python package of the same name (because they have the same API and same functionality, just different implementations). I want to be able to report which one is currently installed and in use along with its version. importlib.metadata
seems to have the functionality I want, but from my testing it appears to just do a case and punctuation insensitive search on the distribution name, which works in the most of the time case where they are the same, but which can never be able to distinguish two distributions sharing the same absolute import path. I have also glanced at the implementation which shows an awful lot of abstraction, but not any other currently implemented options. Sigh. It’s enough to make one want to go back to writing shell scripts.