pass callback from python to c++ using boost::python

Ok, I’m still trying to figure this out too, but here’s whats working for me so far: #this is the variable that will hold a reference to the python function PyObject *py_callback; #the following function will invoked from python to populate the call back reference PyObject *set_py_callback(PyObject *callable) { py_callback = callable; /* Remember new … Read more

Runtime error R6034 in embedded Python application

The problem was caused by third-party software that had added itself to the path and installed msvcr90.dll in its program folder. In this case, the problem was caused by Intel’s iCLS Client. Here’s how to find the problem in similar situations: Download Process Explorer here. Start your application and reproduce runtime error R6034. Start Process … Read more

std::vector to boost::python::list

boost::python already includes functionality for wrapping vectors and maps. Here’s sample code for vectors, as you can see both passing and returning lists is quite simple: // C++ code typedef std::vector<std::string> MyList; class MyClass { MyList myFuncGet(); void myFuncSet(const Mylist& list); // stuff }; // Wrapper code #include <boost/python/suite/indexing/vector_indexing_suite.hpp> using namespace boost::python; BOOST_PYTHON_MODULE(mymodule) { class_<MyList>(“MyList”) … Read more

How to import python module from .so file?

take that ‘hello_world.so’ file and and make new python file (in the same dir) named as ‘hello_world.py’. Put the below code in it.. . def __bootstrap__(): global __bootstrap__, __loader__, __file__ import sys, pkg_resources, imp __file__ = pkg_resources.resource_filename(__name__,’hello_world.so’) __loader__ = None; del __bootstrap__, __loader__ imp.load_dynamic(__name__,__file__) __bootstrap__() now you can import this hello_world as: >>> import hello_world

How to get Python exception text

Well, I found out how to do it. Without boost (only error message, because code to extract info from traceback is too heavy to post it here): PyObject *ptype, *pvalue, *ptraceback; PyErr_Fetch(&ptype, &pvalue, &ptraceback); //pvalue contains error message //ptraceback contains stack snapshot and many other information //(see python traceback structure) //Get error message char *pStrErrorMessage … Read more

Ubuntu – Linking boost.python – Fatal error: pyconfig cannot be found

I just had the same error, the problem is g++ can’t find pyconfig.h(shocking, I know). For me this file is located in /usr/include/python2.7/pyconfig.h so appending -I /usr/include/python2.7/ should fix it, alternatively you can add the directory to your path with: export CPLUS_INCLUDE_PATH=”$CPLUS_INCLUDE_PATH:/usr/include/python2.7/” You can also add this to your .bashrc and it will be added … Read more

tech