can not import numpy in boost-python

风流意气都作罢 提交于 2019-12-13 00:52:48

问题


I am trying out boost-python. However, even a simple hello world doesn't work.

#define BOOST_PYTHON_STATIC_LIB
#include <boost/python/detail/wrap_python.hpp>
#include "numpy/arrayobject.h"
#include <boost/python.hpp>

 void init_numpy()
{
  import_array();
}

 int main()
 {
     Py_Intialize();
     init_numpy();       

 }

It gives error

ImportError: numpy.core.multiarray failed to import

But if I open my IPython, and run import numpy.core.multiarray, it runs fine. What part am I getting worng?


回答1:


I solved the problem by by realizing that the Anaconda2 on my windows was not registered during installation (even sys.path is the same as that in IPython), I uninstalled it and reinstalled it, during installation I chose to register in the windows, now my code is working fine.



来源:https://stackoverflow.com/questions/42938191/can-not-import-numpy-in-boost-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!