Error when Importing tensorflow in embedded python in c++

China☆狼群 提交于 2019-12-19 10:42:39

问题


My question is regarding embedding Python 3.5 interpreter in a C++ program to receive an image from C++, and use it as an input for my trained tensorflow model. When I import tensorflow library in my python code I get an error (other libraries work fine). The simplified code is as follows:

#include <string>
#include <windows.h>
#include <stdio.h>


int main()
{
    Py_InitializeEx(1);

    PyObject* sysPath = PySys_GetObject((char*)"path");
    PyObject* curDir = PyUnicode_FromString(".");
    PyList_Append(sysPath, curDir);
    Py_DECREF(curDir);


    PyRun_SimpleString("import tensorflow\n"
        "print(tensorflow.__version__)\n");


    Py_Finalize();
    return 0;
}

And the error is:

ConsoleApplication5.exe - Ordinal Not Found

The ordinal 225 could not be located in the dynamic link library libiomp5md.dll.

OK

And after pressing OK, this error appears in console:

Intel MKL FATAL ERROR: Cannot load mkl_intel_thread.dll.

My setup is on Windows 7 x64, Anaconda Python 3.5.2, tensorflow-1.1.0 and CUDA 8.

This is a similar problem with a different error.

Thanks for your help.


回答1:


I've fixed this problem by copying libiomp5md.dll from python library folder to directory of my C++ code.



来源:https://stackoverflow.com/questions/46190234/error-when-importing-tensorflow-in-embedded-python-in-c

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