c++ - import error in embedding python with boost python -


i have following code

#include <boost/python.hpp>  int main() {     py_initialize();     namespace python = boost::python;     try {         python::object main = python::import("sample");     } catch(...) {         pyerr_print();         pyerr_clear();     } } 

i following error:

importerror: no module named sample 

i put sample.py @ same directory program.

it's because python::import not looking inside current directory. know 2 ways solve it:

set pythonpath inside current directory (linux):

export pythonpath=`pwd`:$pythonpath 

or...

set python search module path inside code (also provides better explanation issue you've found out): how import work boost.python inside python files


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -