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

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -