Error when Importing tensorflow in embedded python in c++

952 views Asked by At

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

There are 1 answers

0
Matin H On BEST ANSWER

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