Hi,
I have small and old piece of ANSI C code which I want to wrap using Cython so that it is callable from Python. I am trying to follow the examples given in Kurt Smith's book, "Cython: A Guide for Python Programmers". However, I am getting compilation errors which I can't figure out. Below is a paste of the errors and I am attaching the 'chemical_element.pyx' file. I would appreciate any help. Thanks. I am using Cython 0.28.4 which has been installed using pip into the Python 3.6.8 which comes with Linux CENTOS 7. My setup.py file looks like this:
setup.py
from distutils.core import setup, Extension
from Cython.Build import cythonize
ext = Extension( name = 'chemical_element', sources = ['chemical_element_c.c', 'chemical_element.pyx'])
setup(extension_modules=cythonize(ext))
Here is how I invoke the compilation:
python3 setup.py build_ext --inplace
Compiling chemical_element.pyx because it changed.
[1/1] Cythonizing chemical_element.pyx
Error compiling Cython file:
------------------------------------------------------------
...
double atomic_weight
int lookup_element_by_name( chemical_element *e, char *name )
int lookup_element_by_z( chemical_element *e, int z )
def get_element_by_name( char *elem_symb ):
^
------------------------------------------------------------
chemical_element.pyx:15:4: Expected an identifier, found 'def'
Error compiling Cython file:
------------------------------------------------------------
...
else:
ret_val = None
return ret_val
def get_element_by_atomic_number( int atomic_num ):
^
------------------------------------------------------------
chemical_element.pyx:28:4: Expected an identifier, found 'def'
Traceback (most recent call last):
File "setup.py", line 5, in <module>
setup(extension_modules=cythonize(ext))
File "/usr/local/lib64/python3.6/site-packages/Cython/Build/Dependencies.py", line 1026, in cythonize
cythonize_one(*args)
File "/usr/local/lib64/python3.6/site-packages/Cython/Build/Dependencies.py", line 1146, in cythonize_one
raise CompileError(None, pyx_file)
Cython.Compiler.Errors.CompileError: chemical_element.pyx
boyle:/arse% python3
Python 3.6.8 (default, Apr 25 2019, 21:02:35)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux
Type "help", "copyright", "credits" or "license" for more information.