Cythonize dynamic pyx function
<p>I've created a <code>pyx</code> file dynamically, but struggle to cythonize and use the function encoded in it.</p>

<p>I tried </p>

<pre><code>import pyximport
pyximport.install()
import imp
module = imp.load_source('module.name', pyxfilename)
</code></pre>

<p>but this doesn't seem to work. Any idea how can I do this?</p>

<p>You could use the function <code>pyximport.load_module</code> instead of <code>imp.load_source</code> (<a href="https://github.com/cython/cython/blob/151d653d3c7ab07e9d961c9601b2ff45202e6ce2/pyximport/pyximport.py#L207" rel="nofollow">https://github.com/cython/cython/blob/151d653d3c7ab07e9d961c9601b2ff45202e6ce2/pyximport/pyximport.py#L207</a>). </p>

<p>That appears to build if required then call <code>imp.load_dynamic</code>. You call it in the same way as <code>load_source</code> e.g.</p>

<pre><code>module = pyximport.load_module('module.name', pyxfilename)
</code></pre>

python cython