c++:找不到 numpy/arrayobject.h 和 Python.h



我正在尝试编译以下c++文件

#include <iostream> 
#include <Python.h>
#include <numpy/npy_math.h>

using namespace std; 
int main() 
{ 

cout << "Hello World" << endl;    // prints value of i 
}

和下面的

clang++ main.cpp -std=c++1y

返回:main.cpp:3:10: fatal error: 'Python.h' file not found

然后我找到了这个解决方案Mac OS X 10.6缺少Python.h头文件然后我把文件改成

#include <iostream> 
#include <Python/Python.h>
#include <numpy/npy_math.h>
using namespace std; 
int main() 
{ 
cout << "Hello World" << endl;    // prints value of i 
}
main.cpp:3:10: fatal error: 'numpy/npy_math.h' file not found

好的,然后我找到numpy和

的路径
clang++ main.cpp -std=c++1y -I /Users/nicolas/opt/anaconda3/lib/python3.7/site-packages/numpy/core/include

则返回

/Users/nicolas/opt/anaconda3/lib/python3.7/site-packages/numpy/core/include/numpy/npy_common.h:11:10:致命错误:'Python.h' file not found# include & lt; Python.h>

有人能帮我吗?

您可以通过打开npy_common.h并将#include <Python.h>更改为#include <Python/Python.h>#include <../../Python/Python.h>或该文件的相对路径来快速修复此问题,甚至将文件Python.h复制到Users/nicolas/opt/anaconda3/lib/python3.7/site-packages/numpy/core/include/numpy/文件夹

未找到文件的原因是npy_common.h正在同一目录

中查找Python.h

最新更新