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

Pybind - Curiously Recurring Template

I have the following Class structure (simplified example of my actual implementation): /* TestClass.hpp */ #pragma once template class CurRecTemplate { protected: CurRecTemplate() {} ~CurRecTemplate() {} Impl& impl() {…
Phil-ZXX
  • 2,359
  • 2
  • 28
  • 40
0
votes
1 answer

Python and C++ (Pybind11): Python Extension Module Import Error

I try to wrap a C++ - function with pybind to create a python-module. After compiling with Visual Studio I accomplished to create a .pyd file. I tried to import this file (python>>> import pymodule) but get this error: Import Error: dynamic module…
user8757434
0
votes
1 answer

Conversion Error from 'unsigned __int64' to 'unsigned __int64 *' - Pybind11

After downloading this https://github.com/pybind/pybind11/archive/v2.2.3.zip and creating a simple cpp file: #include int add(int i, int j) { return i + j; } PYBIND11_MODULE(example, m) { m.doc() = "pybind11 example…
Phil-ZXX
  • 2,359
  • 2
  • 28
  • 40
0
votes
1 answer

Remove a default compiler option when building with setup.py

I am exposing my C++ code to Python using pybind11. Let's say I'm doing exactly the example provided by the pybind developers. In the end, I'm building using python setup.py build The compiler is invoked with clang ... -DNDEBUG ... -O3 ... -I...…
Tom de Geus
  • 5,625
  • 2
  • 33
  • 77
0
votes
1 answer

Eigen parameters passing by reference

I'm following this page in the Eigen documentation an trying to understand the use of Eigen parameters https://eigen.tuxfamily.org/dox/TopicFunctionTakingEigenTypes.html The following code works as expected #include #include…
shanksk
  • 115
  • 4
0
votes
2 answers

pytest and pybind11: can't import c++ extension

I use pybind11 to add a module _cxx to existing python library liba. The liba._cxx.func doesn't exist until I compile the c++ extension and install the whole library by setup.py. When I run tests in liba/tests/test__cxx.py, it complains that it…
R zu
  • 2,034
  • 12
  • 30
0
votes
1 answer

Segfault when using pybind11 wrappers in C++

I have an example with the following structure. ├── CMakeLists.txt ├── ext │   └── pybind11 └── main.cpp CMakeLists.txt cmake_minimum_required(VERSION 3.5) project(notworking) add_subdirectory(ext/pybind11) add_executable(notworking …
Eric Hansen
  • 1,749
  • 2
  • 19
  • 39
0
votes
1 answer

CMAKE Linking dynamic library to module, but not showing as link dependency

Point me in the right direction if this has been asked before. I have lib1 and mod2, which must be linked together. This project is spread to a couple of folders and a couple of CMakeLists.txt files. The cmake commands that I am using are as…
errolflynn
  • 641
  • 2
  • 11
  • 24
0
votes
1 answer

embedding Python in C++ using pybind11, Segmentation fault

I'm trying to embed Python in C++ using pybind11. Embedding got a lot less attention than extension, and useful resources are hard to find. Here's my naive code #include "Python.h" #include "pybind11/pybind11.h" #include namespace py =…
zpz
  • 354
  • 1
  • 3
  • 16
0
votes
1 answer

PYBIND11_PLUGIN Already has a body

I have a problem and I need help finding a solution. What I'm currently doing I'm trying to use PyBind11 to send a several variables from C++ to Python (Which is then used to log sql data, but that's besides the point). I am am to do this using the…
ekcell
  • 105
  • 2
  • 11
0
votes
1 answer

Interface C/C++ using different Python tools

So I am doing a project that requires me to write some python codes to interface C/C++ programs, but I haven't decided which tool I should use. Intuitively, I'd like to choose between pybind11 and Boost.Python. Programmers: what are the pro and con…
user4234904
-1
votes
0 answers

Pybind segfault when passing list back from Python

EDITED: I am trying to bind the function that is allocating #include #include #include "pybind11/numpy.h" #include #include struct Dummy { Dummy() : data1(1), data2(2) {}; int…
Valeria
  • 1,508
  • 4
  • 20
  • 44
-1
votes
0 answers

python hangs when script finished

To communicate some production system from Python I developed an extension using C++ and Pybind11. The functionality itself working fine. But(!) the python.exe process itself hangs when script finished. Currently script is very simple, I'm using it…
dmitry_bond
  • 378
  • 1
  • 3
  • 15
-1
votes
1 answer

CMake doesn't create .pyd not .dll file. Why is that?

I am currently trying use pybind11 to connect my C++ code on my Windows 10 machine to my Python code. But when I open the cmake-gui it comiles successfully, but doesn't create the expected .pyd file. CMakeLists.txt cmake_minimum_required (VERSION…
-1
votes
1 answer

How can I force CMake to use Python executables and libs from a given folder?

I have both Python 3.6 in "C:\PYTHON_VERSIONS\STANDARD_3.6.8" and 3.8 in "C:\Python\3.8" in my system. I want to compile pybind11 using 3.6 but CMake takes lib directories from 3.6 and the executable from 3.8! a very bad mix indeed. Here is output…
DEKKER
  • 877
  • 6
  • 19