How to specify Python 3 source in Cython's setup.py?

后端 未结 3 1749
孤城傲影
孤城傲影 2020-12-01 06:04

I am trying to do a "Hello World" program in Cython, following this tutorial http://docs.cython.org/src/tutorial/cython_tutorial.html#cython-hello-world

I c

3条回答
  •  日久生厌
    2020-12-01 06:46

    If you are using a setup.py with Extension, as in this example

    from distutils.core import setup
    from distutils.extension import Extension
    from Cython.Distutils import build_ext
    
    ext_modules = [
        Extension("mymodule1",  ["mymodule1.py"]),
        Extension("mymodule2",  ["mymodule2.py"]),
    ]
    
    setup(
        name = 'My Program Name',
        cmdclass = {'build_ext': build_ext},
        ext_modules = ext_modules
    )
    

    then you have to add the following snippet to apply the language_level directive (BEFORE the setup(...), thanks codeman48):

    for e in ext_modules:
        e.cython_directives = {'language_level': "3"} #all are Python-3
    

提交回复
热议问题