问题描述
我正在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 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: How can I solve this problem? Is the structure of the You need to call setup.py with Python 3 ( 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编译错误:动态模块未定义模块导出功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!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),
)
setup.py
the reason why this is not compiling? 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.