Cython: ImportError: No module named 'myModule': how to call a cython module containing a cimport to another cython nodule?

后端 未结 2 1430
轻奢々
轻奢々 2020-12-23 22:49

I\'m trying to import a cython module data.pyx into another cython module user.pyx. Everything compile fine, but when I try to call user.pyx in a python module, I am getting

相关标签:
2条回答
  • 2020-12-23 22:54

    I encounter this problem again in an another project. To solve it, here is what I did:

    • all import and cimport statement must be fully qualified
    • all the python code must be contained in a rootFolder
    • the setup.py must be at the same level than the rootFolder
    • all folder in the rooFolder including the rootFolder must contains a __init__.py
    • in your setup.py the extension's include_dirs must contains '.'

    I created a simple project which illustrates this here.
    This page helped me created it.
    But my project is simpler and I think it would have helped me a lot if I had it.
    My project also illustrate how to automatically build all cython files in a project.

    0 讨论(0)
  • 2020-12-23 23:18

    I might be missing something about Cython, but I think it's:

    import package.user
    user.doSomething()
    
    0 讨论(0)
提交回复
热议问题