https://blog.csdn.net/ztf312/article/details/77340300
此时用python setup.py build_ext --inplace编译时报错如下:
Cython fatal error C1083: 无法打开包括文件: “numpy/arrayobject.h”: No such file or directory
解决方法:
添加 include_dirs=[np.get_include()]
调用c++文件和调用c文件基本相同,唯一不同要指定语言,另外name最好和pyx的name一致
setup.py
""" @author:Zhao @ide:PyCharm @createTime:2019-03-13 """ from distutils.core import setup, Extension from Cython.Build import cythonize import numpy as np ext = Extension(name="UIPCC", sources=["UIPCC.pyx", "c_UIPCC.cpp"], language="c++", ) # cythonize:编译源代码为C或C++,返回一个distutils Extension对象列表 setup(ext_modules=cythonize(ext), include_dirs=[np.get_include()])