Cython编译错误:动态模块未定义模块导出功能 [英] Cython Compilation Error: dynamic module does not define module export function

查看:457
本文介绍了Cython编译错误:动态模块未定义模块导出功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在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中未编译,但出现以下错误:

动态模块未定义模块导出功能

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

解决方案

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

请参见动态模块未定义init函数(PyInit_fuzzy)如何指定Cython的setup.py中的Python 3源代码?

I am building a package in Cython. I am using the following as the structure for 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),
)

However, I am getting an error upon installation in Python 3. It is working in Python 2 however, it is not compiling in Python 3 having the following error:

dynamic module does not define module export function

How can I solve this problem? Is the structure of the setup.py the reason why this is not compiling?

You need to call setup.py with Python 3 (python3 setup.py build_ext, maybe --inplace). It's because Python 3 defines a different name for the init function called when the module starts, and so you need to build it using Python 3 to ensure the correct name is generated.

See dynamic module does not define init function (PyInit_fuzzy) and How to specify Python 3 source in Cython's setup.py? for slightly more detail (it's bordering on a duplicate of these questions, but isn't quite in my view)

这篇关于Cython编译错误:动态模块未定义模块导出功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆