Python 3.x 删除setup.py中的Cython断言选项
我的Cython(Python 3.x 删除setup.py中的Cython断言选项,python-3.x,cython,Python 3.x,Cython,我的Cython(.pyx)文件包含assert,我想在编译该文件时将其删除。我找到并编辑了我的setup.py,如下所示 from distutils.core import setup from distutils.extension import Extension from Cython.Distutils import build_ext # Before edit compiler_args = ["-O3", "-ffast-math"] # Both did not work
.pyx
)文件包含assert
,我想在编译该文件时将其删除。我找到并编辑了我的setup.py
,如下所示
from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext
# Before edit
compiler_args = ["-O3", "-ffast-math"]
# Both did not work
# compiler_args = ["-O3", "-ffast-math", "-DPYREX_WITHOUT_ASSERTIONS"]
# compiler_args = ["-O3", "-ffast-math", "-CYTHON_WITHOUT_ASSERTIONS"]
ext_modules = [
Extension("mycython", sources=["mycython.pyx"],
extra_compile_args=compiler_args)
]
setup(
name="Test",
cmdclass={'build_ext': build_ext},
ext_modules=ext_modules
)
错误显示:
clang: error: unknown argument: '-CYTHON_WITHOUT_ASSERTIONS'
如何修复它?
CYTHON\u没有断言
是一个预处理器宏,因此必须使用-D
标志将其传递给clang
(就像gcc
)。第一个变量的名称实际上是PYREX\u,没有任何断言
,但要将其作为宏(即clang
编译器的一部分)传递给预处理器,需要在变量名称前面添加-D
尝试使用compiler\u args=[“-O3”、“-ffast math”、“-DCYTHON\u WITHOUT\u断言”]
(注意CYTHON\u WITHOUT\u断言前面的D
)
HTH.你说的“不工作”是什么意思?如果您有一个完整的可复制示例,包括pyx@chrisb谢谢你指出!我更新了问题!