I have written a program in C++ which uses python embeddings in order to call a python module, which utilizes the numpy and pytorch libraries. When using solely the numpy library I can successfully call and return from the module without any errors. However, when I add the "import torch" command on my module, my program throws the following error:
DEBUG: caught signal to interrupt (Child exited).
The problem also occurs when I import torch/sklearn modules using the PyRun_SimpleString() function.
Part of my program where I call the respective imports:
Py_Initialize();
PyRun_SimpleString("import numpy");
cout << "numpy ok" << endl;
PyRun_SimpleString("import torch");
cout << "torch ok" << endl;
When I execute the code above, I get the following output:
numpy ok
DEBUG: caught signal to interrupt (Child exited).
I compile and link my program using the python3-config --cflags
and python3-config --ldflags` outputs.
I have also pytorch installed for my python3.6 as can be seen from the code below:
PyRun_SimpleString("import importlib");
PyRun_SimpleString("flag = importlib.util.find_spec('torch')");
PyRun_SimpleString("print(flag is not None)");
This code prints True
, showing the torch is actually installed but for some reason can not be loaded.
Finally, the same behavior occurs when trying to import the sklearn library. Thank you.