cython setuptools集成
cython-setuptools的Python项目详细描述
cython设置工具
易于cython模块的分布和开发。
功能:
- 两个分发模型:包含在包中的C/C++文件,以及 没有
- cython模块在
setup.cfg
中定义
- 直接从cython源安装,而不在目标中安装cython
环境(cython只包含在
install_requires
)
安装
$ pip install cython-setuptools
用法
下面是一个使用默认分发模型的示例python包(仅 cython文件包含在源包中)。
首先在包中安装cython-setuptools
供应商模块,旁边是
setup.py
。
$ cd your-python-project/
$ cython-setuptools install
然后在setup.py
:
cython-setuptools
setup()
fromcysetuptoolsimportsetupsetup()
注意,这里保留setup()
的默认cythonize=True
参数,
这意味着C文件是从cython文件自动编译而来的。
{< CD10> }将意味着我们需要分发C/C++文件
从源包中的cython编译而来。
在setup.cfg
中定义cython模块。
[metadata]name=your-python-projectversion=1.0[options]packages=find:install_requires=cython[options.extras_require]dev=cython[cython-defaults]include_dirs=include/[cython-module: foo.bar]sources=foo.pyx bar.cppinclude_dirs=eval(__import__('numpy').get_include())language=c++pkg_config_packages=opencv
然后,您的cython模块可以编译并使用以下命令进行测试:
$ python setup.py build_ext --inplace
这会自动编译过时的cython文件。如果setup(cythonize=False)
使用时,必须明确告诉安装程序重新编译过时的cython
文件:
$ CYTHONIZE=1 python setup.py build_ext --inplace