How to compile and link multiple python modules (or packages) using cython?

后端 未结 1 549
终归单人心
终归单人心 2020-12-23 22:55

I have several python modules (organized into packages), which depend on each other. e.g.

  • Module1
  • Module2: imports Module1
  • M
相关标签:
1条回答
  • 2020-12-23 23:33

    Edit. First two options refer to Cython's specific code, what I've missed is that the question is about pure python modules, so option 3 is the solution.

    There are a few options:

    1. See this "How To Create A Hierarchy Of Modules In A Package": https://github.com/cython/cython/wiki/PackageHierarchy

    2. I prefer the "include" statement: http://docs.cython.org/src/userguide/language_basics.html#the-include-statement I have many .pyx files and they are all included in main.pyx, it's all in one namespace. The result is one big module: http://code.google.com/p/cefpython/source/browse/cefpython.pyx

    3. You can compile all your modules at once using setup by adding more than one "Extension":

    setup(
        cmdclass = {'build_ext': build_ext},
        ext_modules = [Extension("example", sourcefiles), Extension("example2", sourcefiles2), Extension("example3", sourcefiles3)]
    )
    

    4. A more efficent compilation - see here.

    setup (
        name = 'MyProject',
        ext_modules = cythonize(["*.pyx"]),
    )
    
    0 讨论(0)
提交回复
热议问题