python 3.x - Cython relative import error, even when doing absolute import -


i'm having trouble in cython (with python 3.5) importing between modules in single package.

the error i'm getting systemerror: parent module '' not loaded, cannot perform relative import, when i'm apparently doing absolute imports.

below simple test setup i'm using. works fine using pure-python version of below (.py rather .pyx , no compilation), not compiled through cython. note i'm not using cython language features in below example, compilation.

it seems there's structure i'm not getting quite right? can't figure out how working properly.

file structure:

packagemain  |  +--__init__.py  (this empty)  +--packagemain.pyx  +--somemodule.pyx  +--setup.py 

file packagemain.pyx

from packagemain.somemodule import someclass2  # same error relative import, ie .somemodule  class someclass1:       def __init__(self):           foo = someclass2() 

file somemodule.pyx:

class someclass2:       def __init__(self):           print("whoop!") 

file setup.py:

from distutils.core import setup, extension cython.build import cythonize  extensions = [  extension(language="c++", name="packagemain",                 sources=["packagemain.pyx", "somemodule.pyx"])]  setup(  name = 'some name',         ext_modules = cythonize(extensions) ) 

running from packagemain import packagemain using .pyd file produced cython results in above error.

with following code / definitions,

>>> mytest import mainmodule >>> dir(mainmodule) ['someclass1', 'someclass2', '__builtins__', '__doc__',  '__file__', '__loader__', '__name__', '__package__', '__spec__', '__test__'] 

setup.py

from distutils.core import setup, extension cython.build import cythonize  extensions = [  extension(language="c++",                 name="mytest.mainmodule", sources=["mytest.mainmodule.pyx"]),                 extension(language="c++",                 name="mytest.somemodule", sources=["mytest.somemodule.pyx"])]  setup(  name = 'mytest',         ext_modules = cythonize(extensions) ) 

mytest.mainmodule.pyx

class someclass1:       def __init__(self):           foo = someclass2() 

mytest.somemodule.pyx

class someclass2:       def __init__(self):           print("whoop!") 

when python loads extension module abc, expects find function named initabc called initialize module. if 2 c++ files generated cython compiled , put same shared library, init function of other cython-based module not called, , module not found.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -