作者Philethan (Ethan)
看板C_and_CPP
标题[问题] 'numpy/arrayobject.h' file not found
时间Mon Aug 12 23:49:43 2019
开发平台(Platform): (Ex: Win10, Linux, ...)
MacOS Mojave 10.14.6
编译器(Ex: GCC, clang, VC++...)+目标环境(跟开发平台不同的话需列出)
Xcode Version 10.3
额外使用到的函数库(Library Used): (Ex: OpenGL, ...)
matplotlib-cpp
https://github.com/lava/matplotlib-cpp
问题(Question):
长话短说:想要在C++上画简单的 y=f(x) 图,例如 y=3x^2 之类的。
所以想说用这个函数库,看起来是从Python来的,而我先前就经常用
Python。但没想到一直遇到问题。首先是找不到Python.h,後来在前面
加上 Python/ 就解决了。但後来就变成找不到 numpy/arrayobject.h,
即便我确实有在 Finder 中找到这个档案,也试着在 Search_Header_Path
加入该路径,但还是没有效果..
细节:
执行其Github上最简单的第一个范例时,就出现了错误
https://github.com/lava/matplotlib-cpp
#include "matplotlibcpp.h"
namespace plt = matplotlibcpp;
int main() {
plt::plot({1,3,2,4});
plt::show();
}
错误讯息都发生在执行 matplotlibcpp.h 的时候。
最初的错误是:
'Python.h' file not found
这时的指令为
#include <Python.h>
但在我将 include 的内容改为
#include <Python/Python.h> 之後就ok了。
(参考自
https://reurl.cc/YLAno)
可是就发生了第二个错误讯息:
'numpy/arrayobject.h' file not found
在作者Github上也有网友提出相同问题,作者是说只要你设定好正确档案路径
就可以了(
https://github.com/lava/matplotlib-cpp/issues/46)。
後来我试着在 terminal 中进入 Python,然後
>>>
import numpy as np
>>>
np.get_include()
'/Users/Ethan/Library/Python/3.6/lib/python
/site-packages/numpy/core/include'
於是我将上述路径新增到
Xcode >> Project >> build settings >> target >> Search Header Path
不论是底下的 debug,还是 release,我将上述路径去掉前後单引号後直接贴上。
结果不但没解决问题,反而还使我找不到 Python.h,设定仍为
#include<Python/Python.h>
'Python.h' file not found
很神奇的是,如果我将上述路径的 /include 去掉,那就找得到 Python.h
也就是说,Python.h 看起来好像是位於 .../numpy/core 资料夹中,但我
从 Finder 去看,却找不到 Python.h,所以我也搞不懂为什麽去掉 /include
之後就没有出现
'Python.h' file not found 错误讯息。
话说回来,就算去掉了/include,还是会出现错误讯息:
'numpy/arrayobject.h' file not found
但是我可以肯定/include之中确实有 /numpy/arrayobject.h 这个档案,
因为我有直接在 Finder 看见它。
总之这真的是太奇怪了,抱歉我第一次使用,可能问到蠢问题 QQ
我有Google满多资料,包括有人提到将上述 np.get_include() 得到的路径
直接放入 Cflags 环境变数中(
https://github.com/hmmlearn/hmmlearn/issues/43)。
我有照着做,在 terminal 输入底下这行
export CFLAGS="-I /Users/Ethan/Library/Python/3.6/lib/python/
site-packages/numpy/core/include $CFLAGS"
然後在 terminal 输入 env 检查是否设定好环境变数,也是有。
目前真的不知道该怎麽做才好了 QQ 还请各位大神帮帮我 感谢大大 <(__)>
我只是想要用 c++ 画图 QQ
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 123.192.0.245 (台湾)
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/C_and_CPP/M.1565624990.A.3F3.html
※ 编辑: Philethan (123.192.0.245 台湾), 08/12/2019 23:56:26