用户警告:未知扩展选项:“cython_directives”本地安装 Cython 包时
我正在使用 Cython 版本 0.29.26。 我有一个带有 Cython 扩展的 python 包,如下所示:
./setup.py:
from setuptools import setup, find_packages, Extension
from setuptools.command.build_ext import build_ext
import numpy as np
cython_directives = {'boundscheck': "False",
'cdivision': "True",
'wraparound': "False",
'language_level': "3"}
setup(name='debug_example',
packages=find_packages(),
cmdclass={'build_ext': build_ext},
ext_modules=[
Extension('debug_example.example',
sources=['debug_example/example.pyx'],
language='c++',
include_dirs=[np.get_include()],
cython_directives=cython_directives,
)
]
)
./debug_example/example.pyx
cimport numpy as np
cpdef int increment(int a):
return a + 1
./debug_example/__init__ .py
:
from .example import increment
当我编译它时,我收到一条关于 cython_directives 未知的警告消息(除此之外,编译工作正常)。 pip install -e 的输出。 -v:
(base) ➜ debug_cython pip install -e . -v
Using pip 21.2.4 from /home/mm/anaconda3/lib/python3.9/site-packages/pip (python 3.9)
Obtaining file:///home/mm/tmp/debug_cython
Running command python setup.py egg_info
/home/mm/anaconda3/lib/python3.9/site-packages/setuptools/_distutils/extension.py:131: UserWarning: Unknown Extension options: 'cython_directives'
这是什么原因?
I am using Cython version 0.29.26.
I have a python package with a Cython extension as follows:
./setup.py:
from setuptools import setup, find_packages, Extension
from setuptools.command.build_ext import build_ext
import numpy as np
cython_directives = {'boundscheck': "False",
'cdivision': "True",
'wraparound': "False",
'language_level': "3"}
setup(name='debug_example',
packages=find_packages(),
cmdclass={'build_ext': build_ext},
ext_modules=[
Extension('debug_example.example',
sources=['debug_example/example.pyx'],
language='c++',
include_dirs=[np.get_include()],
cython_directives=cython_directives,
)
]
)
./debug_example/example.pyx
cimport numpy as np
cpdef int increment(int a):
return a + 1
./debug_example/__init__.py
:
from .example import increment
When I compile it, I get a warning message about cython_directives
being unknown (compilation works fine apart from that).
Output of pip install -e . -v
:
(base) ➜ debug_cython pip install -e . -v
Using pip 21.2.4 from /home/mm/anaconda3/lib/python3.9/site-packages/pip (python 3.9)
Obtaining file:///home/mm/tmp/debug_cython
Running command python setup.py egg_info
/home/mm/anaconda3/lib/python3.9/site-packages/setuptools/_distutils/extension.py:131: UserWarning: Unknown Extension options: 'cython_directives'
what is the cause of this ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Extension
来自setuptools
,它对 Cython 的支持有些有限:它会自动为*.pyx
文件调用cythonize
但对于更多选项,应该直接使用 cythonize 。这意味着您的 setup.py 具有以下内容:即可以将compiler_directives 传递给 cythonize。
Extension
is fromsetuptools
which has somewhat limited support for Cython: it automatically invokescythonize
for*.pyx
-files but for more options one should usecythonize
directly. That means the following for yoursetup.py
:I.e.
compiler_directives
can be passed to cythonize.