Python/Cython trouble importing files and methods -
there 2 issues both relating importing may or may not cython related?
i have next simplified files recreate problem. files in same directory. .pyx files have compiled *.so, *.pyc , *.c files.
setup.py:
from distutils.core import setup cython.build import cythonize setup( ext_modules=cythonize("*.pyx"), )
cy1.pyx: (cython)
cdef int timestwo(int x): homecoming x * 2
cy1.pxd:
cdef int timestwo(int x)
cy3.py: (normal python)
def tripleit(x): homecoming x*3
go.py:
from cy1 import timestwo print str(timestwo(5))
gives me error: importerror: cannot import name timestwo
if alter to:
go.py:
import pyximport; pyximport.install() import cy1 print str(cy1.timestwo(5))
it tells me: attributeerror: 'module' object has no attribute 'timestwo'
if take out cython , seek utilize normal python phone call cy3.py:
go.py:
import cy3 print str(cy3.tripeleit(3))
i get: attributeerror: 'module' object has no attribute 'tripeleit'
and lastly if do:
go.py:
from cy3 import tripleit print str(tripeleit(3))
i get: nameerror: name 'tripeleit' not defined
sorry if super basic cannot seem figure out :(
the problem in go.py
:
from cy1 import timestwo print str(timestwo(5))
you trying import function defined cdef
.
to expose function python have either utilize def
or cpdef
. perchance have maintain cdef
in order cimport
other cython files, justifying why have pxd
file. in case have c
-like function , wrapper can called python.
in case cy1.pyx
file like:
cdef int ctimestwo(int x): homecoming x * 2 def timestwo(x): # <-- little wrapper expose ctimestwo() python homecoming ctimestwo(x)
and cy1.pxd
file:
cdef int ctimestwo(int x)
such can cimport
ctimestwo
function.
python python-2.7 cython importerror
No comments:
Post a Comment