title: python - How to use python call function in pyx file
body: <p>I am new to cython.</p>
  
  <p>Now, I am trying to import standard c library and define a simple function in pyx file:</p>
  
  <pre><code>from libc.math cimport sin
  
  cdef double f(double x):
      return sin(x*x)
  </code></pre>
  
  <p>I compiled with this file:</p>
  
  <pre><code>from distutils.core import setup
  from distutils.extension import Extension
  from Cython.Distutils import build_ext
  
  ext_modules=[
      Extension("demo",
                ["demo.pyx"],
                libraries=["m"]) # Unix-like specific
  ]
  
  setup(
    name = "Demos",
    cmdclass = {"build_ext": build_ext},
    ext_modules = ext_modules
  )
  </code></pre>
  
  <p>and generate a library called demo.so
  now I am trying to call this "f" function in a python file:</p>
  
  <pre><code>import demo
  print demo.f(2)
  </code></pre>
  
  <p>The compiler said,</p>
  
  <pre><code> Traceback (most recent call last):
    File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  AttributeError: 'module' object has no attribute 'f'
  </code></pre>
  
  <p>Does anyone know, how can I call the function in pyx file? thanks!</p>