ImportError on Cython submodule

坚强是说给别人听的谎言 提交于 2019-12-11 02:54:47

问题


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'] 
)

来源:https://stackoverflow.com/questions/23841937/importerror-on-cython-submodule

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!