4

I'm trying to follow this basic cython tutorial. In my directory I've
--> __ init__.py
-->hello.pyx
-->setup.py

Iniside hello.pyx-

print "Hello World"

Inside setup.py

from distutils.core import setup
from Cython.Build import cythonize
setup(ext_modules = cythonize("hello.pyx"))

When I exceute python setup.py build_ext --inplace I'm getting this error-

F:\bots\cython>python setup.py build_ext --inplace
Compiling hello.pyx because it changed.
Cythonizing hello.pyx
Error compiling Cython file:
------------------------------------------------------------
...
^
------------------------------------------------------------

cython:0:0: cython.hello is not available

Traceback (most recent call last):



File "setup.py", line 5, in <module>
ext_modules = cythonize("hello.pyx")
  File "C:\Anaconda2\lib\site-packages\Cython\Build\Dependencies.py", line 778,in cythonize
      cythonize_one(*args[1:])
  File "C:\Anaconda2\lib\site-packages\Cython\Build\Dependencies.py", line 895, in cythonize_one
      raise CompileError(None, pyx_file)
      Cython.Compiler.Errors.CompileError: hello.pyx

It worked once and it generated hello.pyd as well but after this I installed few packages (tensorflow and others) using conda. But since then its not working and giving above error.

I've the mingw installed using conda

1 Answer 1

3

Try removing __init__.py from that directory. For some reason, it confuses cython when trying compilation.

You can also consider using pyximport extension, like: import pyximport; pyximport.install(), and then import your_module(as if it was a normal .py) if you just wish to import the .pyx files from normal python files. (In the latter case, __init__.py doesn't have to be removed.)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.