Import my cythonized package in python
<p>I have a script_function_cython.pyx file containing a single function:</p>

<pre><code>import numpy as np
import scipy.misc as misc
import matplotlib.pyplot as plt

def my_function(img, kernel):

    assert kernel.shape==(3, 3)

    res = np.zeros(img.shape)

    for i in range(1, img.shape[0]-1):
        for j in range(1, img.shape[1]-1):

            res[i, j] = np.sum(np.array([[img[i-1, j-1], img[i-1, j], img[i-1, j+1]],
                                 [img[i, j-1], img[i, j], img[i, j+1]],
                                [img[i+1, j], img[i+1, j], img[i+1, j+1]]])*kernel)

    return res






if __name__ == '__main__':

    kernel = np.array([[-1, -1, -1], [-1, 3, -1], [-1, -1, -1]])
    img = misc.face()[:256, :256, 0]
    res = my_function(img, kernel)

    plt.figure()
    plt.imshow(res, cmap=plt.cm.gray)
</code></pre>

<p>I have thus created a setup.py file:</p>

<pre><code>from distutils.core import setup
from Cython.Build import cythonize

setup(
    ext_modules = cythonize('script_function_cython.pyx'),  
)
</code></pre>

<p>Then, I compile it:</p>

<pre><code>python setup.py build_ext --inplace
</code></pre>

<p>And install it:</p>

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

<p>However, when I try to further import it,</p>

<pre><code>import script_function_cython
</code></pre>

<p>I get:</p>

<pre><code>ImportError: No module named script_function_cython
</code></pre>

<p>with the <code>--inplace</code> build there is no need for install. You'll need to import from project directory though.</p>

<pre><code>python setup.py build --inplace
python -c 'import script_function_cython'
</code></pre>

<p>should raise no error.</p>

python numpy cython distutils