我正在创建一个setup.py
具有一些 Cython 扩展模块的项目的文件。
我已经让它工作了:
from setuptools import setup, Extension
from Cython.Build import cythonize
setup(
name=...,
...,
ext_modules=cythonize([ ... ]),
)
这安装得很好。但是,这假设已安装 Cython。如果没有安装怎么办?我明白这就是setup_requires
参数用于:
from setuptools import setup, Extension
from Cython.Build import cythonize
setup(
name=...,
...,
setup_requires=['Cython'],
...,
ext_modules=cythonize([ ... ]),
)
但是,如果 Cython 尚未安装,这当然会失败:
$ python setup.py install
Traceback (most recent call last):
File "setup.py", line 2, in <module>
from Cython.Build import cythonize
ImportError: No module named Cython.Build
执行此操作的正确方法是什么?我需要以某种方式导入Cython
仅在之后setup_requires
步骤运行,但我需要Cython
为了指定ext_modules
values.