Questions tagged [pybind11]

pybind11 is a C++/Python package offering seamless operability between C++11 and Python, in the spirit of “boost::python” but without the heavy-duty Boost dependency.

pybind11 — Seamless operability between C++11 and Python.

The following core C++ features can be mapped to Python:

  • Functions accepting and returning custom data structures per value, reference, or pointer
  • Instance methods and static methods
  • Overloaded functions
  • Instance attributes and static attributes
  • Many more…

In addition to the core functionality, pybind11 provides some extra goodies:

  • Python 2.7, 3.x, and PyPy (PyPy2.7 >= 5.7) are supported with an implementation-agnostic interface.
  • It is possible to bind C++11 lambda functions with captured variables. The lambda capture data is stored inside the resulting Python function object.
  • pybind11 uses C++11 move constructors and move assignment operators whenever possible to efficiently transfer custom data types.
  • Still more…

Supported compilers:

  • Clang/LLVM (any non-ancient version with C++11 support)
  • GCC 4.8 or newer
  • Microsoft Visual Studio 2015 or newer
  • Intel C++ compiler v15 or newer

See documentation at https://pybind11.readthedocs.io/en/latest/index.html

1040 questions
4
votes
2 answers

How to set python function as callback for c++ using pybind11?

typedef bool (*ftype_callback)(ClientInterface* client, const Member* member ,int member_num); struct Member{ char x[64]; int y; }; class ClientInterface { public: virtual int calc()=0; virtual bool join()=0; virtual bool…
HALF9000
  • 518
  • 2
  • 14
4
votes
1 answer

how to check if a py::object isinstance of python decimal.Decimal in pybind11 with python3.9?

I'm new to pybind11, want to detect if a py::object isinstance of python's decimal.Decimal. How could I write it in C++ pybind11 module ?
linrongbin
  • 2,967
  • 6
  • 31
  • 59
4
votes
2 answers

pybind11: send MPI communicator from Python to CPP

I have a C++ class which I intend to call from python's mpi4py interface such that each node spawns the class. On the C++ side, I'm using the Open MPI library (installed via homebrew) and pybind11. The C++ class is as follows: #include…
Jarwin
  • 1,045
  • 1
  • 9
  • 30
4
votes
1 answer

pybind11 implicitly_convertible does not work

I am struggling to make the simplest example work. Here is my code: // example.cpp #include namespace py = pybind11; class B { public: int b; }; class A { public: int a; A(int a) :a(a) {} A(B b) { a = b.b;…
Mircode
  • 432
  • 5
  • 12
4
votes
0 answers

Generating documentation using Sphinx and `sphinx.ext.autosummary` recursively for external `pybind11` module

I am having issues with generating documentation using Sphinx for a python package which contains an external c++ module which uses pybind11 to generate the Python bindings. The problem I have is that the compiled module contains several submodules,…
esocrats
  • 178
  • 5
4
votes
1 answer

How to structure and distribute Pybind11 extension with stubs?

I'm trying to create and distribute (with pip) a Python package that has Python code, and C++ code compiled to a .pyd file with Pybind11 (using Visual Studio 2019). I also want to include .pyi stub files, for VScode and other editors. I can't find…
wolfinabox
  • 83
  • 1
  • 4
4
votes
2 answers

Return Array of Eigen::Matrix from C++ to Python without copying

I have some C++ code that generates and manipulates arrays of Eigen matrices. In the end I want to use those matrices in python and thought this might be a job for pybind11. Basically what I want back in python are two nested lists / numpy…
scleronomic
  • 4,392
  • 1
  • 13
  • 43
4
votes
0 answers

"plugin needed to handle lto object" problem when creat python wrapper with MinGW 32 bits

I'm trying to build a python wrapper of a shared C++ library using pybind11, with MinGW 32 bits. It seems pybind11 enabled LTO, see the configure result from CMake bellow: The C compiler identification is GNU 9.2.0 The CXX compiler identification is…
Fay
  • 105
  • 1
  • 5
4
votes
1 answer

How can you bind exceptions with custom fields and constructors in pybind11 and still have them function as python exception?

This appears to be a known limitation in pybind11. I read through all the docs, whatever bug reports seemed applicable, and everything I could find in the pybind11 gitter. I have a custom exception class in c++ that contains custom constructors and…
Jesse C
  • 779
  • 4
  • 11
4
votes
3 answers

Debugging Pybind11 extension with Visual Studio Code (MacOS)

I've been using pybind11 recently, and now that I'm getting the hang of it, I'm thrilled with it. It's an awesome piece of work. The final piece of the tool puzzle for doing pybind11 is the debug part. I've got command line debugging with lldb…
4
votes
1 answer

ImportError: DLL load failed with pybind11 and PCL

I'm using pybind11 to create a Python wrapper for a small C++ class. I'm getting the following error when importing the DLL (running python -v to show Traceback): >>> from a_py import * Traceback (most recent call last): File "", line 1, in…
Adi Shavit
  • 16,743
  • 5
  • 67
  • 137
4
votes
1 answer

"No module named pybind11" after installing pybind11

I have installed pybind11 (several different ways, including pip and the package manager) on my Ubuntu 18.04.3 machine, but when I try to specify include files the recommended way: python3 -m pybind11 --includes I get this error: /usr/bin/python3:…
Madwand
  • 49
  • 1
  • 1
  • 4
4
votes
2 answers

pybind11 - Wrapping overloaded assignment operator?

I'm using pybind11 to expose C++ functions to a Python interface. I want to wrap the overloaded assignment operator but don't know how. The documentation and examples provided don't really cover it, at least from what I saw. Here's a simplified…
adriyens
  • 39
  • 4
4
votes
1 answer

pybind module.obj: error LNK2001: unresolved external symbol

when I run pip install . in the directory where I have my setup.py. I'm using pybind11 to build a python module for my C++ project. (also, on windows 10) I get this error: https://pastebin.com/xGyFQQk2 Here is the module.cpp code: Environment…
Dyllan M
  • 301
  • 2
  • 15
4
votes
0 answers

Releasing the GIL in PyBind11 for multithreading in Python with OpenMP

I am using Pybind11 and trying to use OpenMP in it. I call a c++ function from Python using the PyBind interpreter and GIL, then I compute a multithreaded for loop with OpenMP in c++, in which I call within each thread a python function. To do so, I…
Joachim
  • 490
  • 5
  • 24