title: Find (installed) distribution package that contains a module
body: <p>Suppose, I have a following Python project that is build with <code>setuptools</code>:</p>
  <pre><code>$ tree proj
  proj
  ├── foo
  │   ├── bar.py
  │   └── __init__.py
  └── pyproject.toml
  </code></pre>
  <pre class="lang-ini prettyprint-override"><code># pyproject.toml
  [build-system]
  requires = [&quot;setuptools&gt;=45.0&quot;]
  build-backend = &quot;setuptools.build_meta&quot;
  
  [project]
  name = &quot;proj&quot;
  version = &quot;0.1.0&quot;
  </code></pre>
  <p>So, the distribution package <code>proj</code> provides a package <code>foo</code> with one module <code>foo.bar</code>.</p>
  <p>Given that I install the project with <code>pip</code> in the current virtual environment, how can I map (dynamically) the module <code>foo.bar</code> to its distribution <code>proj</code>?</p>
  <p><em><strong>Note</strong></em>. I'd like the solution to be robust against the fact that multiple distributions can provide the same package (e.g. via <a href="https://packaging.python.org/en/latest/guides/packaging-namespace-packages/" rel="nofollow noreferrer">namespace packages</a>). In the case above, just suppose that I have two distributions that are structured as follows (note the absense of <code>__init__.py</code> inside of <code>foo</code>s):</p>
  <pre><code>$ tree proj1 proj2
  proj1
  ├── foo
  │   └── bar1
  │       └── __init__.py
  └── pyproject.toml
  proj2
  ├── foo
  │   └── bar2
  │       └── __init__.py
  └── pyproject.toml
  </code></pre>
  <p>and thus I'd like to map</p>
  <pre><code>foo.bar1 -&gt; proj1
  foo.bar2 -&gt; proj2
  </code></pre>