Python 3.x 删除setup.py中的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

我的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
# 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谢谢你指出!我更新了问题!