Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
588 views
in Technique[技术] by (71.8m points)

python - Cython Compilation Error: dynamic module does not define module export function

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...