Install SWIGged Python library into dist-packages/myfoo.py, not dist-packages/myfoo/myfoo.py
<p>I have a directory structure like</p>

<pre><code> setup.py
 myfoo/
     myfoo.i
     myfoo.cpp
     myfoo.hpp
</code></pre>

<p>with <code>setup.py</code>,</p>



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

setup(
    name='myfoo',
    ext_modules=[
        Extension(
            '_myfoo',
            [
                'myfoo/myfoo.cpp',
                'myfoo/myfoo.i'
            ],
            swig_opts=['-c++'],
            )
        ],
    version='0.0.1',
    packages=['myfoo'],
    requires=[]
    )
</code></pre>

<p><code>myfoo.hpp</code></p>



<pre><code>#ifndef MYFOO_HPP
#define MYFOO_HPP

int myfoo();

#endif  // MYFOO_HPP
</code></pre>

<p><code>myfoo.cpp</code></p>



<pre><code>#include "myfoo.hpp"

#include &lt;iostream&gt;

int myfoo() {
  std::cout &lt;&lt; "hey!" &lt;&lt; std::endl;
  return 42;
}
</code></pre>

<p>When running <code>python setup.py install</code>, the package builds correctly and installs the files</p>

<pre><code>/usr/local/lib/python2.7/dist-packages/
    _myfoo.so
    myfoo/
        myfoo.py
        myfoo.pyc
</code></pre>

<p>By default, only <code>/usr/local/lib/python2.7/dist-packages/</code> is in the <code>$PYTHONPATH</code>, so <code>import myfoo</code> from anywhere yields an import error. For that to work, either both <code>myfoo.py[c]</code> should be in <code>/usr/local/lib/python2.7/dist-packages/</code> or be renamed to <code>__init__.py</code>. It seems that I didn't call <code>setup.py</code> correctly.</p>

<p>Any hints?</p>

<p>Removing</p>



<pre><code>packages=['myfoo'],
</code></pre>

<p>and adding</p>



<pre><code>py_modules = ['myfoo'],
package_dir = {'' : 'myfoo'}
</code></pre>

<p>to <code>setup.py</code> does the trick.</p>

python c++ swig distutils