【发布时间】:2021-07-06 20:52:47
【问题描述】:
我已使用 cpython setup.py 方法将 .pyx 文件转换为 .pyd,但总是收到以下消息:
ValueError: no signature found for builtin <built-in function hello>
我正在转换的文件 test.pyx :
from pyxll import xl_func
@xl_func
def hello():
return "HELLO WORLD"
setup.py 脚本:
from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext
ext_modules = [
Extension("example.test", sources=["example/test.pyx"])
]
setup(
name='Example',
cmdclass={'build_ext': build_ext},
ext_modules=ext_modules
)
当我尝试导入此测试模块时,我收到了指定的消息。 虽然当我尝试在没有导入和装饰器的情况下转换 test.pyx 时它可以正常工作,但安装程序中是否需要任何特定的配置更改才能包含 pyxll。
环境:Python 3.8.5 32 位
【问题讨论】:
-
你在 pxd 文件中放了什么?另外,你的函数是静态编译的python代码;为什么?
-
你的 pxd 是指 pyx 文件??
-
你说
I have converted a .pyx file to .pyd using cpython setup.py method。 Cython 使用pxd文件进行定义,pyx文件用于实现(您也可以在所谓的pure-mode中使用.py,但这是另一回事)。但是,cython 不使用pyd文件。 -
@cvanelteren 感谢您提供我不知道的信息....因为您说 .py 有效,所以我尝试了它并且有效。
-
请记住,这不是 python 中的首选方式。带有
pxd文件的py称为纯模式,请参见此处cython.readthedocs.io/en/latest/src/tutorial/pure.html。
标签: python-3.x cython