How to find assets of installed pip package
<p>While deploying my application, I need to install a library which contains some assets that must be served from an static directory. That means, during the deploy, I must do the following:</p>

<ol>
<li><code>pip install</code> the package</li>
<li>Find the <em>absolute</em> location where the package has been installed (this is usually <code>site-packages</code> in the virtualenv or global location)</li>
<li>Copy the assets from the installed package to the static directory</li>
</ol>

<p>Is there a portable way of doing step 2? The only starting piece of data that I have to find the installed package is <code>pip</code> / <code>python</code>.</p>

<p>Is there a way to tell <code>python</code>: in what absolute location have you installed a certain package?</p>

<p>If you install package <code>abc</code>, you should be able to import that package and get its base location in a python program with:</p>

<pre><code>import abc
import os
print(os.path.dirname(abc.__file__))
</code></pre>

<p>if importing is not possible because of some side-effect this might have you 
can walk <code>sys.path</code> and look for <code>abc.py</code> or <code>abc/__init__.py</code>.</p>

<p>If you have multiple installations, you might not find the version you just installed, but in that case you also would not be running that when importing <code>abc</code>, but an older version.</p>

python pip