How should I structure a Python package that contains Cython code

后端 未结 10 1858
傲寒
傲寒 2020-12-22 15:11

I\'d like to make a Python package containing some Cython code. I\'ve got the the Cython code working nicely. However, now I want to know how best to package it.

For

10条回答
  •  清歌不尽
    2020-12-22 15:21

    The simple hack I came up with:

    from distutils.core import setup
    
    try:
        from Cython.Build import cythonize
    except ImportError:
        from pip import pip
    
        pip.main(['install', 'cython'])
    
        from Cython.Build import cythonize
    
    
    setup(…)
    

    Just install Cython if it could not be imported. One should probably not share this code, but for my own dependencies it's good enough.

提交回复
热议问题