c++ run python code to import custom module -
c++ run python code to import custom module -
i new writing c++/python mixed programs.
i have compiled my_class.so (in c++) , can import in python.
the next programs run without problem.
#!/user/bin/env python my_class import * l = my_class() l.dosomething("filename")
i have under same folder , if start python environment, can next without error
>>>import my_class
this tried next, tried phone call python scripts c++, "hello" , "import numpy" part run without problem.
next tried purely experimental, want test possibility, don't expect real application, want import own class. following(i know creating c++/python/c++ chain):
#include <python.h> int main(int argc, char *argv[]){ py_initialize(); //pyrun_simplestring("print \"hello!\""); //pyrun_simplestring("import numpy"); pyrun_simplestring("import my_class"); py_finalize(); homecoming 0; }
i got next error:
traceback (most recent phone call last): file "<string>", line 1, in <module> importerror: no module named my_class
this not total surprise, since my_class not standard module , need tell python runtime within c++ programme find module.
but not sure how can it. assume @ to the lowest degree can seek "install" my_class.so custom module in python's standard path, wonder if there simpler solution. thanks!
after making .so
can install my_class.so
checkout this post , this post.
python c++ boost-python
Comments
Post a Comment