Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to resolve error "error compiling Cython file" error?

Tags:

python

cython

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

like image 527
swapnil jariwala Avatar asked Oct 15 '25 04:10

swapnil jariwala


1 Answers

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.)

like image 92
Mudragreas Avatar answered Oct 17 '25 16:10

Mudragreas