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

Boost.Python Hello World on Mac OS X

I am trying to setup and compile the Hello World example for Boost.Python: http://www.boost.org/doc/libs/1_57_0/libs/python/doc/tutorial/doc/html/python/hello.html I installed bjam, boost, boost-build, and boost-python from Homebrew: brew install…
Wesley Tansey
  • 4,555
  • 10
  • 42
  • 69
11
votes
4 answers

building boost python examples using Visual Studio 2008

I'm using Boost Python library to create python extensions to my C++ code. I'd like to be able to invoke from python the 'greet' function from the C++ code shown below: #include #include char const*…
jf.
  • 111
  • 1
  • 4
11
votes
2 answers

Exposing C++ interface in boost python

Sample code to illustrate: struct Base { virtual int foo() = 0; }; struct Derived : public Base { virtual int foo() { return 42; } }; Base* get_base() { return new Derived; } BOOST_PYTHON_MODULE(libTestMod) { …
balki
  • 26,394
  • 30
  • 105
  • 151
11
votes
4 answers

Boost.Python - How to return by reference?

I'm using Boost.Python to create Python modules from C++ classes. And I ran into a problem with references. Condider the following case where I have a class Foo with overloaded get methods that can either return by value or reference. Specifying…
mandrake
  • 1,213
  • 1
  • 14
  • 28
10
votes
2 answers

Checking whether a converter has already been registered

I have several modules which define converters for some trivial types (such as list of ints as std::vector); they are parts of independent modules, but they are sometimes both used in one script, which leads to RuntimeWarning: to-Python…
eudoxos
  • 18,545
  • 10
  • 61
  • 110
10
votes
4 answers

How to tell what python version libboost_python.so is using?

I'd like to know what version of python boost_python.so is expecting. This is on a computer with multiple python versions and I did not build/install boost myself (nor do i have root access). How can i tell what version of python boost_python.so is…
Anthony Bak
  • 1,123
  • 3
  • 10
  • 16
10
votes
2 answers

boost::python and weak_ptr : stuff disappearing

I would like to store a reference to an object as a weak_ptr. In pure C++, the following works : #include #include #include using namespace std; using namespace boost; struct Empty { …
girodt
  • 369
  • 1
  • 10
10
votes
4 answers

Hello world with boost python and python 3.2

So I'm trying to interface python 3.2 and c++ using boost python, and have come across many many issues. I've finally gotten it to compile using the 2.7 libraries and it works, but I can't seem to make it work with python 3.2. Here's the c++…
Dwight
  • 360
  • 1
  • 3
  • 15
10
votes
1 answer

How to override the automatically created docstring data for Boost::Python?

I am currently working developing a C++-based module for Python. I have found that Boost::Python is working quite well for what I want to accomplish. However, I am now running into some issues with the docstring that is being generated by…
MarkD
  • 4,864
  • 5
  • 36
  • 67
10
votes
2 answers

Passing Python list to C++ vector using Boost.python

How do I pass a Python list of my object type ClassName to a C++ function that accepts a vector? The best I found is something like this: example. Unfortunately, the code crashes and I can't seem to figure out why. Here's what I…
Neil G
  • 32,138
  • 39
  • 156
  • 257
10
votes
2 answers

Python* to boost::python::object

I am trying to build a Python module in C++ that transforms a 2D vector into a Numpy 2D array. What is incorrect here - presumably there is some transformation needed to a boost python object from PyObject*? boost::python::object build_day(int year,…
timbo
  • 13,244
  • 8
  • 51
  • 71
10
votes
1 answer

Building/including Boost.Python in VS2013

Can someone tell me if I'm doing anything wrong. I'm on Windows 7 using Visual Studio 2013 and I would like to be able to be able to setup a simple Boost.Python project. I don't know if I've made something wrong building boost or when including…
Adelost
  • 2,343
  • 2
  • 23
  • 28
10
votes
2 answers

Boost.Python: Wrap functions to release the GIL

I am currently working with Boost.Python and would like some help to solve a tricky problem. Context When a C++ method/function is exposed to Python, it needs to release the GIL (Global Interpreter Lock) to let other threads use the interpreter.…
Rippalka
  • 380
  • 6
  • 16
10
votes
5 answers

Need help getting started with Boost.Python

I'm trying to build my first Boost.Python example. #include #include using namespace boost::python; class Hello { public: std::string greet() { std::cout << "Hello World" << std::endl; …
clstaudt
  • 21,436
  • 45
  • 156
  • 239
9
votes
2 answers

boost::python::list length

Is there any way to calculate length of list passed from python to C++? I want do do something like this, but list class lacks length (or anything similar) method: class Awesome{ public: void awesomeMethod(const boost::python::list&…
KCH
  • 2,794
  • 2
  • 23
  • 22