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
16
votes
1 answer

Class-scoped enum

I have a c++ class with an enum inside, and I wanted to mimick that with boost::python, so that I can write MyClass.value in python. boost::python::class_ does not have an enum_ method, and I was looking for workarounds. I first tried with lambdas…
eudoxos
  • 18,545
  • 10
  • 61
  • 110
16
votes
3 answers

Boost::Python- possible to automatically convert from dict --> std::map?

I've got a C++ class, with a member function that can take a small-to-large number of parameters. Lets name those parameters, a-f. All parameters have default values. As a part of the python project I am working on, I want to expose this class to…
MarkD
  • 4,864
  • 5
  • 36
  • 67
16
votes
1 answer

Boost.python vs Cython for C++/python interface

I know this has been asked a thousand times, however i need to choose a library that can expose C++ functions and methods to python. Considering my application, which mainly is a scientific (matrix) library, and python generator's matureness,…
Carmellose
  • 4,815
  • 10
  • 38
  • 56
15
votes
2 answers

Boost.Python custom exception class

I'm implementing a Python extension module using Boost.Python. The module should define its own custom exception classes that inherit Exception. How do I do that?
Johan Råde
  • 20,480
  • 21
  • 73
  • 110
15
votes
3 answers

what is wrong with c++ streams when using boost.python?

Update 2: I'm not sure why this is still being upvoted (March 2014). This appears to be fixed since I asked this question many years ago. Make sure you're using a recent version of boost. UPDATE: Perhaps C++ streams need to be initialized in…
Neil G
  • 32,138
  • 39
  • 156
  • 257
15
votes
3 answers

How to link with Python3 Libs with cmake?

I have Python3 installed via brew install python3. However, cmake cannot find PythonLibs 3. Here's the header of my CMakeLists.txt. cmake_minimum_required(VERSION 3.0) find_package(PythonLibs 3 REQUIRED) When I ran cmake, I got this error…
Fabian
  • 990
  • 3
  • 11
  • 24
15
votes
4 answers

Python embedded in CPP: how to get data back to CPP

While working on a C++ project, I was looking for a third party library for something that is not my core business. I found a really good library, doing exactly what's needed, but it is written in Python. I decided to experiment with embedding…
yoav.aviram
  • 1,802
  • 15
  • 19
15
votes
3 answers

How to compile static library with -fPIC from boost.python

By default, libboostpython.a is compiled without -fPIC. But I have to make a python extension and it is a dynamic library with -fPIC that links to static libraries. How can I compile a static library (libboostpython.a) with -fPIC from boost.python?
simon
  • 569
  • 9
  • 20
14
votes
3 answers

How do I import modules in boost::python embedded python code?

I'm using boost::python to embed some python code into an app. I was able to get print statements or other expressions to be evaluated properly, but when I try to import modules, it is not importing and application is exiting. Further the globals()…
Sahas
  • 10,637
  • 9
  • 41
  • 51
14
votes
1 answer

How to define a Python metaclass with Boost.Python?

The Python C API has the PyObject *PyType_Type object, which is equivalent to type in the interpreter. If I want to define a metaclass in C++, how can I set type as one of its bases in Boost.Python? Also, what other things should I take into…
Paul Manta
  • 30,618
  • 31
  • 128
  • 208
14
votes
2 answers

how to extract a unicode string with boost.python

It seems that the code will crash when I do extract("a unicode string") Anyone know how to solve this?
yelo
  • 271
  • 2
  • 10
14
votes
1 answer

Fatal Python error when using a dynamic version of Python to execute embedded python code

SPOILER: partially solved (see at the end). Here is an example of code using Python embedded: #include int main(int argc, char** argv) { Py_SetPythonHome(argv[1]); Py_Initialize(); PyRun_SimpleString("print \"Hello !\""); …
Caduchon
  • 4,574
  • 4
  • 26
  • 67
14
votes
2 answers

passing C++ classes instances to python with boost::python

I have a library which creates objects (instances of class A) and pass them to a python program which should be able to call their methods. Basically I have C++ class instances and I want to use them from python. Occasionally that object should be…
Emiliano
  • 22,232
  • 11
  • 45
  • 59
14
votes
1 answer

boost-python: How do I provide a custom constructor wrapper function?

I'm using boost-python to create python bindings for a C++ class named CppClass. When necessary, I can route calls to "normal" member functions through little wrapper functions that preprocess the arguments (e.g. extract C++ types from the python…
Stuart Berg
  • 17,026
  • 12
  • 67
  • 99
14
votes
3 answers

Find the type of boost python object

I have been embedding python into c++ and I would like to know if there is a way to find the type of the boost::python::object which is a result after executing a function of a python module. I have my code like this: boost::python::object module_ =…
Uthay Kumar
  • 141
  • 1
  • 4
1 2
3
88 89