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

how to make bind a map on pybind11

i am working on a backtester for crypto in cpp, but the backend is on python and flask, i try to use pybind11 in order to make the cpp work on the backend, here is my bind code namespace py = pybind11; PYBIND11_MAKE_OPAQUE(std::map
mimus
  • 367
  • 4
  • 21
-1
votes
2 answers

is there pybind11 method that has similar properties of PyString_AsString

I am trying to convert the c++ project from boost to pybind11 QString r = QString(PyString_AsString(result));" QString r = QString(py::str(result));
gino247
  • 1
  • 2
-1
votes
1 answer

Strange C++ syntax: setting function output with some value

I was trying to get pybind11 up and running, and I ran across some strange syntax: #include int add(int i, int j) { return i + j; } PYBIND11_MODULE(example, m) { m.doc() = "pybind11 example plugin"; // optional module…
157 239n
  • 349
  • 3
  • 15
-1
votes
1 answer

Pybind11: How to create bindings for a function that takes in a struct as an argument?

Please see below C++ code that I am trying to create python bindings for struct Config { int a; int b; }; void myfunction(const Config &config); Here is what I have so far, PYBIND11_MODULE(example, m) { py::class_(m, "Config") …
user3667089
  • 2,996
  • 5
  • 30
  • 56
-1
votes
1 answer

Get either a single object or list of objects from an argument of PYBIND11 binded c++ function

I'm trying to bind a function that accepts multiple arguments and keyword arguments with PYBIND. The function looks something like this: { OutputSP output; InputSP input; if (args.size() == 1) { input =…
Vlad Keel
  • 372
  • 2
  • 13
-1
votes
1 answer

How to automatically execute chunks of C++ code (ideally from python)

I have ~10k independent and relatively simple .cpp files (let's assume only one 30-line main() function). I want to understand how each of them runs with many different sets of inputs (which they get via cin). In particular, I want to do the…
etal
  • 12,914
  • 4
  • 13
  • 16
-1
votes
1 answer

Accessing c++ objects from python

I have written a flappy bird clone in c++. Now I would like to try writing an AI to play that game. I would really prefer to use python to write the neural network, so I need to figure out some way to access the Bird object from c++. Then I would…
-1
votes
2 answers

add_cuda_library outputing: Unresolved extern function

I am trying to compile a few .cu source files into a python module. Which works fine as long as there is not more than one file. The CMakeLists.txt looks like this: find_package(CUDA) find_package(PythonLibs 3.7…
Cydouzo
  • 445
  • 5
  • 18
-1
votes
1 answer

undefined symbol: PyExc_RecursionError

Traceback (most recent call last): File "/usr/local/lib/python3.5/dist-packages/numpy/core/__init__.py", line 17, in
Pawan
  • 1
  • 1
  • 3
-1
votes
1 answer

Pybind11 + nan Node module conflicting

/usr/include/python3.5m/node.h:19:20: error: expected constructor, destructor, or type conversion before 'PyNode_New' PyAPI_FUNC(node *) PyNode_New(int type); ^ /usr/include/python3.5m/node.h:20:17: error: expected constructor,…
Pawan
  • 1
  • 1
  • 3
-1
votes
2 answers

Using JsonCpp to return data to python with pybind11 produces Symbol not found error in python call

I am attempting to use JsonCpp in order to parse some data before returning it to python (using pybind11). I have managed to get the make file cooperating with recognizing JsonCpp and compiling, but have been unable so far to get rid of the…
Markyroson
  • 109
  • 10
-1
votes
1 answer

Inside method but loop still getting expected unqualified-id error C++

I have a quick question. I have read about "expected unqualified-id" errors and how they occur when a loop is outside of a method. The issue I am having is that the loop is inside a method and I am still getting this? Any assistance would be greatly…
Markyroson
  • 109
  • 10
-2
votes
0 answers

Compiling a shared library with functions that return a pybind11::object

I have an issue when linking a simple main program with a shared library that has a function taking in a pybind11::object as an argument. (only external dependancy is pybind11, I am using gcc version 13.2.0, python version…
Lman96
  • 1
  • 2
-2
votes
0 answers

pybind11:how to pass an int object in python, get string object in c++

I define c++ code here: my_module.def("test", [](const char* s) { auto a = s; }, py::arg("s")); here is python code: my_module.test(1) I got the trace: TypeError: test(): incompatible function arguments. The following argument types are…
Key
  • 1
-2
votes
0 answers

pybind11 performance limit

I have a matrix class in c++ and want to iterate over all pixels, performing some calculations depending on the position in python. I use a callback function to pass in the logic of the calculation from python (using pybind11). I have setup a…
zboson
  • 121
  • 7
1 2 3
69
70