问题
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