title: Place boost python extension inside package
body: <p>I have the following boost python code:</p>
  
  <pre><code>#include &lt;boost/python.hpp&gt;
  
  namespace bp = boost::python;
  
  class PyExtTest
  {
  public:
      std::string get_name() { return m_name; }
      void set_name(std::string const&amp; name) { m_name = name; }
  
  private:
      std::string m_name;
  };
  
  BOOST_PYTHON_MODULE(test_ext)
  {
      bp::class_&lt;PyExtTest&gt;("pet")
          .add_property("name", &amp;PyExtTest::get_name, &amp;PyExtTest::set_name)
          ;
  }
  </code></pre>
  
  <p>which I compile into the the following directory hierarchy using distutils:</p>
  
  <pre><code>build/lib/test_ext.so
  </code></pre>
  
  <p>and then use (with <code>PYTHONPATH</code> set to <code>build/lib</code>) as so:</p>
  
  <pre><code>import test_ext
  a = test_ext.pet
  a.name = 'dog'
  print a.name     # dog
  </code></pre>
  
  <p>When I configure distutils to install <code>test_ext</code> as part of package <code>pkg</code>, python can no longer find the module. I end up with the directory hierarchy:</p>
  
  <pre><code>build/lib/pkg
  build/lib/pkg/__init__.py
  build/lib/pkg/test_ext.so
  </code></pre>
  
  <p>from using a setup script like:</p>
  
  <pre><code>test_module = Extension('pkg.test_ext'
                          , define_macros = module_macros
                          , extra_compile_args = module_compiler_flags
                          , sources = ['pkg/test_ext/test.cpp']
                          , include_dirs = module_include_dirs
                          , library_dirs = module_lib_dirs
                          , libraries = module_libs)
  
  setup (name = 'Test'
         , version = '0.1'
         , description = 'Test'
         , packages = ['pkg']
         , ext_modules = [test_module])
  </code></pre>
  
  <p>but trying to import the module:</p>
  
  <pre><code>import pkg.test_ext
  </code></pre>
  
  <p>results in the error:</p>
  
  <pre><code>ImportError: No module named test_ext
  </code></pre>
  
  <p>If I substitute a pure python module for <code>test_ext</code>, then everything works as expected.</p>
  
  <p>I think I need to change the boost code in some manner to indicate that the <code>test_ext</code> extension is inside the <code>pkg</code> package, but I cannot figure out exactly how to do it.</p>
  
  <p>I tried just moving <code>test_ext.so</code> to the correct location in the <code>build/lib</code> directory hierarchy to get the package layout that I wanted, but the only place it is recognized as a module is directly under <code>build/lib</code>. This is different the <code>.py</code> files, which I can import successfully from wherever I place them in the directory hierarchy.</p>
  
  <p>I am using <code>python 2.7.6</code> and <code>boost 1.55</code>.</p>
  
  <p>Any help is appreciated.</p>