How do I distribute all contents of root directory to a directory with that name
<p>I have a project named <code>myproj</code> structured like</p>

<pre><code>/myproj
    __init__.py
    module1.py
    module2.py
    setup.py
</code></pre>

<p>my <code>setup.py</code> looks like this</p>

<pre><code>from distutils.core import setup

setup(name='myproj',
      version='0.1',
      description='Does projecty stuff',
      author='Me',
      author_email='me@domain.com',
      packages=[''])
</code></pre>

<p>But this places <code>module1.py</code> and <code>module2.py</code> in the install directory.  </p>

<hr>

<p>How do I specify <code>setup</code> such that the directory <code>/myproj</code> and all of it's contents are dropped into the install directory?</p>

<p>In your <code>myproj</code> root directory for this project, you want to move <code>module1.py</code> and <code>module2.py</code> into a directory named <code>myproj</code> under that, and if you wish to maintain Python &lt; 3.3 compatibility, add a <code>__init__</code>.py into there.</p>

<pre><code>âââ myproj
âÂ Â  âââ __init__.py
âÂ Â  âââ module1.py
âÂ Â  âââ module2.py
âââ setup.py
</code></pre>

<p>You may also consider using <a href="https://setuptools.readthedocs.io/en/latest/" rel="nofollow"><code>setuptools</code></a> instead of just distutils.  <code>setuptools</code> provide a lot more helper methods and additional attributes that make setting up this file a lot easier.  This is the bare minimum <code>setup.py</code> I would construct for the above project:</p>

<pre><code>from setuptools import setup, find_packages

setup(name='myproj',
      version='0.1',
      description="My project",
      author='me',
      author_email='me@example.com',
      packages=find_packages(),
      )
</code></pre>

<p>Running the installation you should see lines like this:</p>

<pre><code>copying build/lib.linux-x86_64-2.7/myproj/__init__.py -&gt; build/bdist.linux-x86_64/egg/myproj
copying build/lib.linux-x86_64-2.7/myproj/module1.py -&gt; build/bdist.linux-x86_64/egg/myproj
copying build/lib.linux-x86_64-2.7/myproj/module2.py -&gt; build/bdist.linux-x86_64/egg/myproj
</code></pre>

<p>This signifies that the setup script has picked up the required source files.  Run the python interpreter (preferably outside this project directory) to ensure that those modules can be imported (not due to relative import).</p>

<p>On the other hand, if you wish to provide those modules at the root level, you definitely need to declare <a href="https://docs.python.org/distutils/setupscript.html#listing-individual-modules" rel="nofollow"><code>py_modules</code></a> explicitly.</p>

<p>Finally, the <a href="https://packaging.python.org/" rel="nofollow">Python Packaging User Guide</a> is a good resource for more specific questions anyone may have about building distributable python packages.</p>

python distutils setup.py