C++使用boost python import 其他路径的模块
我们在boost库下,我们很容易可以实现C++与Python的混合编程,现在我们想在C++下使用boost::python::import其他路径下的模块,我们该如何是好呢?
- try
- {
- using namespace boost::python;
- object main_module = import( "__main__" );
- object main_namespace = main_module.attr( "__dict__" );
- //object sys = import( "sys" );
- object ignored = exec(
- "import sys\n"
- "sys.path.append('./python')\n", main_namespace );
- //ignored = exec( "print sys.path", main_namespace );
- }
- catch ( ... )
- {
- PyErr_Print();
- }
- import sys
- sys.path.append('./python')
相关推荐
IT之家 2020-03-11
graseed 2020-10-28
zbkyumlei 2020-10-12
SXIAOYI 2020-09-16
jinhao 2020-09-07
impress 2020-08-26
liuqipao 2020-07-07
淡风wisdon大大 2020-06-06
yoohsummer 2020-06-01
chenjia00 2020-05-29
baike 2020-05-19
扭来不叫牛奶 2020-05-08
hxmilyy 2020-05-11
黎豆子 2020-05-07
xiongweiwei00 2020-04-29
Cypress 2020-04-25
冰蝶 2020-04-20