gpt4 book ai didi

python - Cython 编译错误 : dynamic module does not define module export function

转载 作者:太空狗 更新时间:2023-10-29 17:49:43 27 4
gpt4 key购买 nike

我正在用 Cython 构建一个包。我使用以下作为 setup.py 的结构:

from distutils.core import setup
from distutils.extension import Extension
from Cython.Build import cythonize
import numpy
import scipy

extensions = [
Extension("xxxxx",["xxxx/xxxxx.pyx"],
include_dirs=[numpy.get_include(),"."]),
Extension("nnls",["xxxxx/xxxxx.pyx"],
include_dirs=[numpy.get_include(),"."]),
]

setup(
name='xxxxxx',
version='0.0.0',
description='''********''',
url='xxxxxxx',
author='xxxxx',
author_email='xxxxx',
packages=[
'xxxxx',
],
install_requires=[
'cython',
'numpy',
'scipy',
],
ext_modules=cythonize(extensions),
)

但是,我在 Python 3 中安装时遇到错误。它在 Python 2 中工作,但是在 Python 3 中无法编译,出现以下错误:

dynamic module does not define module export function

我该如何解决这个问题? setup.py 的结构是不编译的原因吗?

最佳答案

您需要使用 Python 3 调用 setup.py(python3 setup.py build_ext,可能是 --inplace)。这是因为 Python 3 为模块启动时调用的 init 函数定义了不同的名称,因此您需要使用 Python 3 构建它以确保生成正确的名称。

参见 dynamic module does not define init function (PyInit_fuzzy)How to specify Python 3 source in Cython's setup.py?有关更多详细信息(它与这些问题的副本接壤,但在我看来并不完全)

关于python - Cython 编译错误 : dynamic module does not define module export function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36723206/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com