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

what does <% %> do in c++?

I'm using cppimport, which is a library that helps importing cpp into python. As described here: https://github.com/tbenthompson/cppimport, it is necesary to put setup_pybind11 into /* */ in the cpp file. /* <% setup_pybind11(cfg) %> */ It appears…
Nickpick
  • 6,163
  • 16
  • 65
  • 116
0
votes
1 answer

Error when linking LibRaw to shared object

So, what i'm actually trying to is to build a shared object, that contains a python-includable-module, generated by pybind11. I got it as far as to have no syntax-errors in CLion, but when i try to compile it, it gives the following…
Tim Hilt
  • 605
  • 5
  • 23
0
votes
1 answer

How to pass list of shared pointers to c++ object in pybind11

I'm building a ml project which will use tensorflow, game rule set controlled by c++ library and python players. I decided to use pybind as translation layer between game rules engine and control layer with players. Here are classes that I tried to…
morynicz
  • 2,322
  • 2
  • 20
  • 34
0
votes
1 answer

How to bind a void array using pybind11

I have a structure as follows struct _name{ void* person[3]; }name; I tried to copy elements into a python array but it didn't work.
tom
  • 61
  • 3
0
votes
1 answer

How to set a new attribute in pybind11 to python object within c++?

I am trying to create a new python class in c++ with pybind11, fill it with data and then return it. For example, take a simple class in python, which is then used in a c++ function call compiled with pybind11. from TEST import func_wrapper class…
raef
  • 51
  • 2
  • 4
0
votes
0 answers

Avoiding pybind11 lifecycle issues

I am writing ReST api requests in Python. These requests are called from and delivered to C++ (Qt) using pybind11. The desired functionality is performing as expected, yet I receive the following warning when executing my script multiple…
Basti Vagabond
  • 1,458
  • 1
  • 18
  • 26
0
votes
3 answers

Calling super().__init__() on subclass of ForceElement causes No constructor defined

I am trying to create a custom ForceElement as follows class FrontWheelForce(ForceElement): def __init__(self, plant): front_wheel = plant.GetBodyByName("front_wheel") front_wheel_node_index = front_wheel.index() …
Rufus
  • 5,111
  • 4
  • 28
  • 45
0
votes
1 answer

C++ python module (based on Pybind11) import error: ModuleNotFoundError

A C++ python module based on pybind11 library cannot be imported anymore in python. It was working until a few weeks ago but not any more (may be since the installation of miniconda). Cannot track the exact point when this stopped working as I was…
lightsunray
  • 409
  • 5
  • 16
0
votes
1 answer

Class with dynamic_attr() cannot pass __dict__ to the external scope

Reproducible example code My c++ code is very simple: struct A { A() { this->a = 0; } py::int_ a; }; struct B { B() {} A sa; }; PYBIND11_MODULE(libdemo_ext, m) { py::class_(m, "A", py::dynamic_attr()) …
0
votes
1 answer

In pybind11, how do you make a py::module known for import?

In an embedded C++ program in pybind11, I'm defining a python module to use as a container for multiple python objects that I don't want to expose to the global namespace. I then want import this module as needed. But it appears that just defining a…
Dov Grobgeld
  • 4,783
  • 1
  • 25
  • 36
0
votes
1 answer

build with google/draco as lib by pybind11

My test project look: . ├── CMakeLists.txt ├── draco ├── pybind11 ├── setup.py └── src |-main.cpp I am writing python wrapper for draco with pybind11 Because I am new to C++, I don't know how to build draco as share lib There is my simple…
binbin
  • 167
  • 2
  • 11
0
votes
1 answer

pybind11 python embed on Windows 10, Fatal Python error: initfsencoding: unable to load the file system codec #1930

When I use PyBind11 to embed Python interpereter, I faced the error: initfsencoding: unable to load the file system codec. The details: OS: Windows 10 1903 18362.356 Python 3.7.4 & Packages: Miniconda installed at…
sejabs
  • 43
  • 5
0
votes
1 answer

PyBind - Python to C++ interface

It makes sense that using PyBind to interface and call C++ code from Python will make the Python code much faster, but does that hold true for Python code being called from C++? In other words, does PyBind only provide the interface and not the…
Moshe Rabaev
  • 1,892
  • 16
  • 31
0
votes
1 answer

How to bind functions which accepts types from external libraries

I am trying to bind a function which accepts Gst Buffer as follows some_function(GstBuffer *buffer) m.def(some_function,&some_function); binded it using the above code, when called from python it says some_function accpets args0:_GstBuffer…
tom
  • 61
  • 3
0
votes
0 answers

Convert pybind numpy array from float to double in place

For a project I have to pass a numpy of dtype float into a pybind function. That float pybind array then gets passed to a function that accepts a pointer to a double as shown here: // this is the pybind signature m.def("example",…
NateW
  • 2,856
  • 5
  • 26
  • 46