【发布时间】:2019-05-13 15:07:26
【问题描述】:
!一切都适用于 language_level=2,但不适用于 language_level=3
我必须用 Cython 包装 c-library,我还想复制库的结构以便更好地理解。所以我想用 pxd 文件创建单独的文件夹。
项目结构如下:
setup.py:
from setuptools import setup, Extension
from Cython.Build import cythonize
from Cython.Distutils import build_ext
from pathlib import Path
setup_file_directory = Path(__file__).resolve().parent
NAME = 'example'
SRC_DIR = "lib"
PACKAGES = [SRC_DIR]
ext = Extension(name=SRC_DIR + ".wrapper.some_code",
sources=[SRC_DIR + "/wrapper/some_code.pyx"]
)
EXTENSIONS = [ext]
if __name__ == "__main__":
setup(
packages=PACKAGES,
zip_safe=False,
name=NAME,
cmdclass={"build_ext": build_ext},
ext_modules=cythonize(EXTENSIONS, language_level=3),
)
some_code.pyx:
from pxd_include.inc_file cimport *
cdef custom_int return_int(custom_int input_int):
print(input_int)
inc_file.pxd:
ctypedef int custom_int
在 setup.py 中使用 language_level=2 一切正常并编译。如果我将其切换为 3,则会出现错误:
这是由于无法导入 language_level=3 的 pxd 文件造成的。如何解决?
【问题讨论】:
-
没有minimal reproducible example 和完整的错误信息只能猜测。
-
@ead 更新了完全可重现的示例
标签: python-3.x cython