2

I don't understand how to make Cython correctly build a single .pyd out of a module with submodules.

The current setup.py gives me import error on the submodule.

I have the setup given below the rule, and I move both cythontest.pyd and submod.pyd to another folder and start the interpreter there. Unfortunately I get this error:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "__init__.py", line 1, in init cythontest (cythontest\__init__.c:981)
ImportError: No module named submod

Here is my code:

cythontest/
    __init__.py
    submod/
         __init__.py

### cythontest/__init__.py

import cythontest.submod

def test():
    print("cythontest/__init__.py/test()")
    cythontest.submod.test()

### cythontest/submod/__init__.py

def test():
    print("cythontest/submod/__init__.py/test()")

### setup.py

from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext

setup(
    name = 'cythontest',
    cmdclass = {'build_ext': build_ext},
    ext_modules = [
          Extension("cythontest",        sources=["cythontest\\__init__.py"])
        , Extension("cythontest.submod", sources=["cythontest\\submod\\__init__.py"])
    ]
    , include_dirs = ['.', 'cythontest']
    , script_args = ['build_ext', '--inplace', '--compiler=mingw32'] 
)
lordkrandel
  • 185
  • 2
  • 8
  • The `import cythontest.submod` will still do a relative import, so your `.pyd` will still have to be in a subfolder of the name `submod` (*I think*). If this is impossible you'll have to explain what you're trying to achieve in particular. – Veedrac May 24 '14 at 16:36
  • import cythontest.submod -> import submod in __ init __ of cythontest. I think you set up a circular import. – mdurant Jul 29 '14 at 17:48

0 Answers0