boost-python

Boost::Python, converting tuple to Python works, vector<tuple> does not

Boost::Python, converting tuple to Python works, vector<tuple> does not Question: I’ve been using Boost::Python for a while, and everything always turned out ok. However yesterday I was trying to find out why a particular type I thought I had registered (a tuple) was giving me errors when I was trying to access it from Python. …

Total answers: 1

Writing Python bindings for C++ code that use OpenCV

Writing Python bindings for C++ code that use OpenCV Question: I’m trying to write a python wrapper for some C++ code that make use of OpenCV but I’m having difficulties returning the result, which is a OpenCV C++ Mat object, to the python interpreter. I’ve looked at OpenCV’s source and found the file cv2.cpp which …

Total answers: 3

How to import python module from .so file?

How to import python module from .so file? Question: [me@hostname python]$ cat hello_world.cc #include <string> #include <Python.h> #include <boost/python.hpp> namespace { std::string greet() { return “Helloworld”; } } using namespace boost::python; BOOST_PYTHON_MODULE(hello_world) { def(“greet”,greet); } [me@hostnmae python]$ g++ -c -fPIC hello_world.cc -I/path/to/boost/headers -I/path/to/python/headers -o hello_world.o [me@hostname python]$ g++ -shared -Wl,-soname,libhello_world.so -o libhello_world.so hello_world.o [me@hostname python]$ …

Total answers: 2

How does import work with Boost.Python from inside python files

How does import work with Boost.Python from inside python files Question: I am using Boost.Python to embed an interpreter in my C++ executable and execute some prewritten scripts. I have got it working so that I can call functions in the python file but the python code I want to use imports external files and …

Total answers: 2

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

pass callback from python to c++ using boost::python Question: I want to pass callback from my python code to c++ I want my code look something like this: In C++ : typedef void (*MyCallback_t) (CallbackInfo); class MyClass {… void setcallback(MyCallback_t cb); … } And to use it in python : import mylib def myCallback(mylib_CallbackInfo): … …

Total answers: 2

Pickling boost python functions

Pickling boost python functions Question: For the use with joblib.Parallel, I need to be able to pickle a boost::python function. When I try to do so, I get a TypeError: can’t pickle builtin_function_or_method objects As far as I understand, the function should be pickled by fully qualified name only. I don’t see why this is …

Total answers: 2

Boost and Python 3.x

Boost and Python 3.x Question: How does boost.python deal with Python 3? Is it Python 2 only? Asked By: BenjaminB || Source Answers: Newer versions of Boost should work fine with Python V3.x. This support has been added quite some time ago, I believe after a successful Google Summer of Code project back in 2009. …

Total answers: 8

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

boost::python: Python list to std::vector Question: Finally I’m able to use std::vector in python using the [] operator. The trick is to simple provide a container in the boost C++ wrapper which handles the internal vector stuff: #include <boost/python.hpp> #include <vector> class world { std::vector<double> myvec; void add(double n) { this->myvec.push_back(n); } std::vector<double> show() { …

Total answers: 4

CMake output name for dynamic-loaded library?

CMake output name for dynamic-loaded library? Question: I’m trying to write cmake rules to build dynamic-loaded library for python using boost.python on linux. I’d like to use ‘foo’ for python module name. So, the library must be called foo.so. But by default, cmake uses standard rules for library naming, so if I write add_library(foo foo.cpp) …

Total answers: 2

How to get Python exception text

How to get Python exception text Question: I want to embed python in my C++ application. I’m using Boost library – great tool. But i have one problem. If python function throws an exception, i want to catch it and print error in my application or get some detailed information like line number in python …

Total answers: 5