我在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调用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?(它接近这些问题的副本,但在我看来并不完全)