Questions tagged [boost-python]

Library for intuitive and tight integration between C++ and Python.

Boost::python is a C++ library offering seamless integration of C++ and Python with reference handling, built-in and user-defined two-way type conversions, Python/C++ exception translation, function overloading, exposing class hierarchies, docstring support and more.

1337 questions
24
votes
3 answers

boost_python import error: module does not define init function

First off: I looked at the related questions, but they are not very helpful unfortunately. I'm trying to wrap an enum and a class from an external library. #include #include using namespace boost::python; #include…
Michael Schubert
  • 2,726
  • 4
  • 27
  • 49
24
votes
2 answers

Polymorphic exception handling: How to catch subclass exception?

I have the following simple hierarchy of two C++ exceptions: class LIB_EXP ClusterException : public std::exception { public: ClusterException() { } ClusterException(const std::string& what) { init(what); } virtual const char* what()…
SkyWalker
  • 13,729
  • 18
  • 91
  • 187
24
votes
4 answers

Boost.Python: How to expose std::unique_ptr

I am fairly new to boost.python and trying to expose the return value of a function to python. The function signature looks like this: std::unique_ptr someFunc(const std::string &str) const; When calling the function in python, I get the…
mario.schlipf
  • 1,257
  • 2
  • 13
  • 29
24
votes
1 answer

Feeding a Python list into a function taking in a vector with Boost Python

I've got a function with the signature: function(std::vector vector); And I've exposed it, but it doesn't take in Python lists. I've looked through the other SO answers, and most involve changing the function to take in…
victor
  • 6,688
  • 9
  • 44
  • 48
22
votes
4 answers

Exposing a C++ class instance to a python embedded interpreter

I am looking for a simple way to expose a C++ class instance to a python embedded interpreter. I have a C++ library. This library is wrapped (using swig for the moment) and I am able to use it from the python interpreter I have a C++ main program…
jineff
  • 472
  • 4
  • 16
22
votes
2 answers

python/c++ - Compiling shared library with cmake and installing with distutils

I have a boost.python project that I compile using cmake and make. It's part of a python module, and I want to be able to install that module using distutils. I have followed the instructions here to create a CMakeLists.txt file that first compiles…
orentago
  • 578
  • 1
  • 7
  • 13
21
votes
1 answer

Boost.Python call by reference : TypeError: No to_python (by-value) converter found for C++ type:

I'm trying to expose my C++ Classes to Python using Boost.Python. Here is a simplyfied version of what i'm trying to do: I have a class A deriving from boost::noncopyable and a second class B with a method that takes a reference to A as an…
Kai
  • 541
  • 1
  • 3
  • 11
21
votes
2 answers

Address sanitizing Boost.Python modules

My project includes a large C++ library and Python bindings (via Boost.Python). The test suite is mostly written on top of the Python bindings, and I would like to run it with sanitizers, starting with ASAN. I'm running macOS (10.13.1 FWIW, but I…
akim
  • 8,255
  • 3
  • 44
  • 60
21
votes
2 answers

Build problems when adding `__str__` method to Boost Python C++ class

I have started to play around with boost python a bit and ran into a problem. I tried to expose a C++ class to python which posed no problems. But I can't seem to manage to implement the __str__ functionality for the class without getting build…
Rickard
  • 1,754
  • 1
  • 12
  • 17
19
votes
3 answers

Wrapping arrays in Boost Python

I have a series of C++ structures I am trying to wrap using boost python. I've run into difficulties when these structures contain arrays. I am trying to do this with minimal overhead and unfortunately I can't make any modifications to the structs…
MarkS
  • 193
  • 1
  • 1
  • 8
18
votes
4 answers

Calling Python functions from C++

I am trying to achieve call Python functions from C++. I thought it could be achieved through function pointers, but it does not seem to be possible. I have been using boost.python to accomplish this. Say there is a function defined in Python: def…
Amar
  • 393
  • 1
  • 5
  • 9
18
votes
2 answers

Wrapping an std::vector using boost::python vector_indexing_suite

I am working on a C++ library with Python bindings (using boost::python) representing data stored in a file. Majority of my semi-technical users will be using Python to interact with it, so I need to make it as Pythonic as possible. However, I will…
Martin Prazak
  • 1,476
  • 12
  • 20
18
votes
4 answers

Using Boost Python & std::shared_ptr

I'm trying to get Boost Python to play nicely with std::shared_ptr. Currently, I'm receiving this error: Traceback (most recent call last): File "test.py", line 13, in comp.place_annotation(circle.centre()) TypeError: No to_python…
Liam M
  • 5,306
  • 4
  • 39
  • 55
17
votes
1 answer

How do you pass kwargs to a boost-python wrapped function?

I have a python function with this signature: def post_message(self, message, *args, **kwargs): I would like to call the function from c++ and pass to it some kwargs. Calling the function is not the problem. Knowing how to pass the kwargs is. Here…
David
  • 9,635
  • 5
  • 62
  • 68
17
votes
2 answers

Boost Python No to_python converter found for std::string

So, I am trying to create a to_python converter that will allow me to return a boost::optional from an exposed function and have it treated as T if the optional is set and None if not. Based on a post I found on C++Sig, I wrote the following…
DRayX
  • 1,043
  • 2
  • 12
  • 19
1
2
3
88 89