Calculate directory path in Python module distribution
<p>I have a Python module distribution (it's an egg) that contains some additional files &amp; directories that I would like to copy during my program's runtime. </p>

<pre><code>âââ mypkg
â   âââ extra_files
â   â      âââ layouts/
â   â      âââ scripts/
â   â      âââ config.yaml
</code></pre>

<p>When <code>mypkg</code> is being used, I would like to copy all contents of <code>extra_files</code> directory to somewhere else on disk. Something like:</p>

<pre><code>shutil.copytree('mypkg/extra_files', destination)
</code></pre>

<p>I've taken a look at <code>pkg_resources</code> however it seem like I can't calculate the path to a directory that way.</p>

<p>How can I calculate the path to files and directories in my distribution package? Do I need to first list all directories and then call <code>pkg_resources.resource_stream</code> on each file in each directory? </p>

<p>I was able to actually do this with <code>__file__</code>, which returns the pathname from which the module was first loaded. I can get the full path to my static directory like this:</p>

<pre><code>import os
directory = os.path.join(os.path.dirname(__file__), 'templates/index.html')
</code></pre>

python module pkg-resources