我使用C ++应用程序中的单个函数调用单个python模块。我正在获得堆栈跟踪。我将它隔离到python模块中的“import h5py”行。如果我在解释器中运行此模块并运行,一切都很好。此外,所有其他导入工作。如果我删除“import h5py”并注释使用它的代码,然后加载模块并从c ++调用该函数,一切正常。
还做了一个test.py,如果我执行此导入并在C ++中加载模块,它也会产生相同的结果。
有没有人见过这样的东西?有没有办法绕过它,因为我真的需要在我的python模块中使用h5py并需要从我们的C ++应用程序调用模块。
Killing process on sync signal: 6, Aborted
BEGIN stack trace
0: /lib64/libpthread.so.0() [0x346620f500]
1: /lib64/libc.so.6(gsignal+0x35) [0x3465e328a5]
2: /lib64/libc.so.6(abort+0x175) [0x3465e34085]
3: /opt/gs/lib/libhdf5.so.8(H5check_version+0x13d) [0x2b8c62611e5d]
4: /opt/gs/epd-7.3/lib/python2.7/site-packages/h5py/h5f.so(inith5f+0x19c1) [0x2b8c8df11481]
5: /opt/gs/epd-7.3/lib/libpython2.7.so.1.0(_PyImport_LoadDynamicModule+0xc2) [0x2b8c61c78312]
6: /opt/gs/epd-7.3/lib/libpython2.7.so.1.0(+0xed290) [0x2b8c61c76290]
7: /opt/gs/epd-7.3/lib/libpython2.7.so.1.0(+0xed531) [0x2b8c61c76531]
8: /opt/gs/epd-7.3/lib/libpython2.7.so.1.0(PyImport_ImportModuleLevel+0x2be) [0x2b8c61c7756e]
9: /opt/gs/epd-7.3/lib/libpython2.7.so.1.0(+0xd447d) [0x2b8c61c5d47d]
10: /opt/gs/epd-7.3/lib/libpython2.7.so.1.0(PyObject_Call+0x68) [0x2b8c61bcef28]
11: /opt/gs/epd-7.3/lib/libpython2.7.so.1.0(PyEval_CallObjectWithKeywords+0x56) [0x2b8c61c5d9a6]
12: /opt/gs/epd-7.3/lib/libpython2.7.so.1.0(PyEval_EvalFrameEx+0x28b8) [0x2b8c61c60f08]
13: /opt/gs/epd-7.3/lib/libpython2.7.so.1.0(PyEval_EvalCodeEx+0x8d2) [0x2b8c61c65c12]
14: /opt/gs/epd-7.3/lib/libpython2.7.so.1.0(PyEval_EvalCode+0x32) [0x2b8c61c65c62]
15: /opt/gs/epd-7.3/lib/libpython2.7.so.1.0(PyImport_ExecCodeModuleEx+0xc2) [0x2b8c61c74c02]
16: /opt/gs/epd-7.3/lib/libpython2.7.so.1.0(+0xec1ce) [0x2b8c61c751ce]
17: /opt/gs/epd-7.3/lib/libpython2.7.so.1.0(+0xeda8d) [0x2b8c61c76a8d]
18: /opt/gs/epd-7.3/lib/libpython2.7.so.1.0(+0xed290) [0x2b8c61c76290]
19: /opt/gs/epd-7.3/lib/libpython2.7.so.1.0(+0xed764) [0x2b8c61c76764]
END stack trace
答案 0 :(得分:0)
不是解决方案,而是我过去使用的可能解决方法:不是调用PyImport_Import()
,而是在调用之前运行
PyRun_SimpleString("import h5py");
如果成功,它将在sys.modules中加载h5py,后续导入将只是获取该字典中的模块。