Embedding Python in C/C++ from anaconda PyThreadState
Trying to embed a python interpreter into a c++ application. Thought it would be straight forward, but I am having trouble I think with linking. The only unusual thing is that I am trying to use a specific Anaconda package. The simple c++ code is:
# include <Python.h>
int main()
{
printf("before initialize");
Py_Initialize();
printf("after initialize");
PyRun_SimpleString("print('Hello from Python')");
Py_Finalize();
return 0;
}
to compile i use:
gcc pythonTest.cc -I/path/to/anaconda/include/python3.6m -L/path/to/anaconda/lib/python3.6/config-3.6m-x86_64-linux-gnu -lm -lpthread -ldl -lutil -lpython3.6m -o pytest
It does compile but when i run the simple program i get:
Fatal Python error: PyThreadState_Get: no current thread
before initializeAborted
I've checked the path that the program sees and it does include the path to the same python executable as I specified with the includes and libs. However, some searching seems to suggest that what python version is getting called is somehow different than what was linked against. I'm kind of at a loss as to how to figure this out.
尝试编译使用:
gcc pythonTest.cc -I/$HOME/anaconda3/include/python3.6m -lpython3.6m
链接地址: http://www.djcxy.com/p/60536.html
上一篇: 在PC浏览器上模拟触摸事件