Should PYTHONPATH include ./build/*?
<p>Running</p>

<pre><code>$ python setup.py build_ext
</code></pre>

<p>with the usual Cython extension configuration creates a <code>build</code> directory and places the compiled modules deep within it.</p>

<p>How is the Python interpreter supposed to find them now? Should <code>PYTHONPATH</code> include those sub-sub-directories? It seems kludgy to me. Perhaps this is meant to work differently?</p>

<p>Presumably, when you write a package containing Cython code, <a href="http://cython.readthedocs.io/en/latest/src/userguide/source_files_and_compilation.html" rel="nofollow">your <code>setup.py</code> will contain something similar to this</a>:</p>

<pre><code>setup(
    ext_modules = cythonize("example.pyx")
)
</code></pre>

<p>(there are some variations, but that's the general idea). When you run </p>

<pre><code>python setup.py install
</code></pre>

<p>or </p>

<pre><code>python setup.py install --user
</code></pre>

<p>You will see it creates binary files (with extensions based on your OS - on mine it will be <code>example.so</code>) and copies them to the standard installation directory (also depending on your OS). </p>

<p>These binary files are therefore already in the import path of your Python distribution, and it can <code>import</code> them like regular modules. </p>

<p>Consequently, you do not need to add the build directory to the path. Just install (possibly with <code>--user</code>, or use virtualenv, if you're developing), and let the extensions be imported the regular way.</p>

python python-2.7 cython distutils pythonpath