【问题标题】:Cannot import cython module which is generated using setup.py无法导入使用 setup.py 生成的 cython 模块
【发布时间】: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


【解决方案1】:

正如@cvanelteren 指出的文件类型是我编译 py 文件的问题,它解决了导入问题

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-26
    • 2021-10-29
    相关资源
    最近更新 更多