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

How to pass a default numpy array argument to a function in pybind11?

I am defining a method that takes py::array_t< double > and py::array_t< bool > as arguments. How can I tell pybind11 to default those arguments to an array of my choice? (say np.array([0, 0, 0])) I have tried adding the default via "Argument"_a =…
polortiz40
  • 391
  • 4
  • 13
0
votes
1 answer

How do I construct python code from a give .pyd output in Visual Studio?

I am trying to develop a project to integrate C++ function with python using Pybind11. I am quite familiar with C++, but not so with Python. I have files with following format which I developed for a C++ project. Output of C++ as: cppproject.pyd C++…
0
votes
1 answer

Error while integrating C++ function onto Python using Pybind11 while using PYBIND11_MODULE

I am trying to integrate C++ function which calculates tan hyperbolic function found in this incredibly useful link https://learn.microsoft.com/en-us/visualstudio/python/working-with-c-cpp-python-in-visual-studio?view=vs-2019 However, when I tried…
0
votes
0 answers

Do you need to have C++ installed to run a Python program with C++ modules?

so i am creating Python software that uses C++ for heavy lifting when needed through pybind11, this however made me think. If I gave this Python app to someone who doesn't have the C++ runtime installed, would it work on his machine or give an error…
Flamyngo
  • 33
  • 2
  • 6
0
votes
1 answer

Cannot Upload C++ extension to Colab

I wrote a C++ extension and wrapped it using PyBind11 and compiled it on my Linux machine which yielded a .so file that works locally; however, I cannot upload that .so file to Colab so I tried it on Windows and got a .pyd file which does not upload…
Grant
  • 125
  • 1
  • 5
0
votes
1 answer

UnicodeDecodeError with pybind11

I am trying to wrap a class which returns a string. class SS { public: SS(const std::string& s) : data_(s.data()), size_(s.size()) {} // Return a pointer to the beginning of the referenced data const char* data() const { return data_;…
alec.tu
  • 1,647
  • 2
  • 20
  • 41
0
votes
0 answers

set compile flags when installing Python + C++ project

When pip-installing a Python project with C++ parts, pip3 install . --verbose --user the typical compile line will be something like x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat…
Nico Schlömer
  • 53,797
  • 27
  • 201
  • 249
0
votes
1 answer

importing std::vector into python using pybind11 gives python error

I'm trying to use pybind11's stl_bind header to no avail. I tried this: #include #include #include #include namespace py = pybind11; PYBIND11_PLUGIN(test) { py::module…
user2602914
  • 301
  • 3
  • 11
0
votes
1 answer

How to modify/access a C++ pointer using Pybind11 in a python script?

We are trying to embed Python as a scripting language into our game engine that is built using C++. The summary of the issue is as follows: Calling a C++ function that returns a pointer, in python results in a null object. We want to directly…
iansmathew
  • 367
  • 1
  • 3
  • 13
0
votes
0 answers

Simple, high-performance, easy to maintain way for interoperability between java and modern C++

I am looking for the best approach for calling modern C++ 11/14 code from java (with callbacks from C++ back to java). What is the best/easiest/fastest performance way to get interoperability between java and C++ 11/14? I have been programming in…
Phil
  • 5,822
  • 2
  • 31
  • 60
0
votes
1 answer

pybind11: Python to C++ Datatype Conversion Not Working

Problem I am trying to convert a list of lists, returned by a python function called inside a C++ code. Though the pybind11 library allows type conversion from python data types to C++ data types, my attempt to convert a list of lists returned by…
0
votes
1 answer

How can I import Python script at Pybind11 when C++ and Python files are not at the same folder?

Example of Files directory: base--> src_c--> Example.cpp (imports myPyExample.py) src_python--> myPyExample.py and I'd like to import python script using pybind11 What is the way to do it? (found only…
GM1
  • 380
  • 3
  • 14
0
votes
1 answer

What is the proper way to include pybind11 embedded module at user class (as part of singleton class)

I have a Linux C++ dynamic library, which is required to pass a compound structure to python, and receive result structure from python to be transferred up to caller application. To get the python interpreter "alive" after library API function…
GM1
  • 380
  • 3
  • 14
0
votes
1 answer

pybind11 union fails 'is_base_of' assert

I'm trying to bind a union with pybind11 and I'm getting a strange error. I'm not sure if i'm hitting a limitation of pybind11, or i'm implementing this incorrectly. Would anyone be able to point me in the right direction? Thanks! #include…
Mr. Buttons
  • 463
  • 1
  • 3
  • 9
0
votes
1 answer

How to mix Python code into a Python extension module

Say I have a Python package mymodule based on a Pybind11 extension where the following code works like a charm after running python setup.py install: from mypackage.subA import foo # foo is written in C++. from mypackage.subB import bar # Same for…
Bendik
  • 1,097
  • 1
  • 8
  • 27