1,166 questions
2
votes
0
answers
42
views
libstdc++.so links error when try to use pybind11/3.0.1 of conan-2 and cpp23 in wsl
In WSL (Ubuntu 24.04), when using Conan to create a package that links pybind11/3.0.1, the resulting executable in the test_package fails to run.
Even if the executable doesn't directly call any ...
3
votes
0
answers
88
views
pybind11: C++ callback from background thread to Python not executed in real time
I'm trying to expose a C++ interface and callback system to Python using pybind11. In C++, everything works as expected: the callback is triggered in real time from a background thread. In Python, ...
4
votes
1
answer
209
views
How do I interrupt a pybind11 exec call?
I am trying to make an application using python code and C++, but I need some kind of protection against infinite loops or too long executions. I tried following some threads and seeing how other ...
1
vote
1
answer
56
views
Pybind11 cannot integrate with Qt 6.9.1
I included Qt 6.9.1 header files and pybind11/pybind11.h in a same file. but then I use python to build a package.(the compiler is MSVC2022 x64 and I only use CMake)
this is part of setup.py:
import ...
1
vote
1
answer
118
views
pybind11 shared_ptr to Python-implemented class calls pure virtual instead of override
I have a ScriptFactory system in which I have an object that creates instances of custom objects created in Python, which are derived from an abstract base class in C++. The objects are created ...
-3
votes
1
answer
138
views
How to step into C++ code from Python using pybind11 in VSCode when using Python C++ Debugger? [closed]
Question:
I am trying to debug a Python script that calls a C++ function through a .pyd module built with pybind11 (compiled using MSVC). I want to set a breakpoint in Python, and when I press Step ...
1
vote
1
answer
170
views
Import .pyd Python module
I realized a C++ project and I used pydbind11. All work fine on Linux (C++ compilation with CMake produces test executables and Python module that works when I import it, installation with pip install ...
3
votes
1
answer
119
views
pybind11: Python callback executed in C++ with parameter modification
I'm working on Python bindings of my C++ library (a mathematical optimization solver) and I'm stuck at a point where I create a Python callback evaluate_constraints() that takes two arguments, pass it ...
4
votes
1
answer
131
views
Binding std::generator<T> with pybind11?
I am trying to bind a std::generator<T> to a Python generator through pybind11, I am using the following currently:
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include ...
0
votes
1
answer
132
views
How to rebuild c++ extension when using pyproject.toml
I have a few C++ extensions for a python library.
Previously, this library was shipped using setup.py and one could recompile via
python setup.py build_ext --inplace if only the C++ files changed.
...
1
vote
1
answer
110
views
in pybind11, how do you test if py::object is a complex number or a callable?
Context: I've recently been using pybind11 to put a python frontend on an old c++ project of mine. This has mostly been a breeze (thanks pybind11 devs!), but there are some areas where I've had to ...
2
votes
1
answer
81
views
Why is the output of id() applied to a Python object returned from C++ via pybind11 unstable?
I am using a holder class to store a std::shared_ptr to another C++ class created in Python thus:
#include <memory>
#include <iostream>
#include <pybind11/pybind11.h>
class Child {
...
1
vote
0
answers
56
views
pybind11: Binding a function with an abstract reference argument
I want to bind a function that takes a lambda (std::function) as an argument. The lambda itself has a reference to an abstract type as an argument. When I attempt to invoke the function in python, I ...
0
votes
0
answers
61
views
cannot open shared object file: No such file or directory with pybind11
I have a python script myscript.py:
import pydmy as tp
pydmy is my pybind11 wrapper dynamic library. pydmy will load another C++ library libabc.so. libabc.so is under the same directory as pydmy.
In ...
0
votes
0
answers
31
views
Exposing `std::variant` as `TypeAlias` with Pybind11
I'm curious if there's a way to avoid repeating myself. I have several classes that are not related by parentage:
#include <pybind11/operators.h>
#include <pybind11/pybind11.h>
#include &...
0
votes
0
answers
80
views
Cannot include default enum values in function method stubs in pyi file using pybind11-stubgen
I am using pybind11-stubgen version 2.5.3 to create a .pyi stub file for the pybind11 C++ wrapper.
The defaults are passed fine to the methods, so my issue is only that the hints provided when using ...
1
vote
1
answer
47
views
Long import time of pybind11 extension
I have a C++ library with a Python interface, generated using pybind11 on a mac with intel processor. The library is compiled into a single shared object kernel.so, with 29MB of size. Importing the ...
2
votes
0
answers
66
views
ImportError: undefined symbol: __powf_finite when importing pyflex extension built via SoftGym/PyFlex
I’m building the SoftGym/PyFlex Python extension with CMake + pybind11 on Ubuntu. The build completes without errors, but when I try:
import pyflex
in the Python shell, I get:
ImportError: /…/softgym/...
5
votes
1
answer
196
views
How to pass a byte buffer from python to C++
I am creating a library in C++ with Python bindings.
The library takes buffer created in Python code and processes it in several ways. On my way to achieve that, I used the example below generated by ...
2
votes
0
answers
81
views
How to combine MkDocs with pybind11 modules?
I'm trying to generate a documentation site for a Python API which is created with pybind11 using MkDocs. This API has also a .cpp API which is generated well.
This is my C++ common header code:
#...
3
votes
0
answers
109
views
Pybind11, Not find Pure Virtual Function Call When Creating Python-derived Instance via C++ Callback
When creating a Python-derived class from a C++ base class (with a pure virtual function) via a callback, the Python override is not invoked. Instead, the program attempts to call the pure virtual ...
3
votes
0
answers
68
views
Python library made with pybind11 from go code throwing ImportError: dynamic module does not define module export function
TLDR I'm trying to make a simple python library that runs go code through pybind11 and CMake
I installed pybind11 through anaconda in a venv goscrapper
IDE is VSCode
here are the steps I took
create ...
0
votes
1
answer
129
views
Access to SymEngine C++ object from the corresponding Python wrappers [closed]
I have written a C++ library that depends on SymEngine (https://github.com/symengine/symengine).
This library API offers functions that have parameter and return variables of types of SymEngine, e.g. ...
2
votes
2
answers
143
views
Pybind11 - Multiple definition of PyInit_module_name
Solved! - Please check the answer.
I wrote a library where headers and python bindings are auto-generated. For example dummy_bind.cpp for dummy_message.h and each _bind.cpp file has PYBIND11_MODULE ...
0
votes
0
answers
64
views
CMake not generating Release and not installing files as wanted
I am building an application using Pybind11 and CMake. I got almost everything to work, but there are two things that I cannot figure out:
1.) No matter what I do, I only get a Debug folder with my ....
1
vote
1
answer
148
views
How to create a python module in C++ that multiprocessing does not support
I am trying and failing to reproduce and understand a problem I saw where multiprocessing failed when using a python module written in C++. My understanding was that the problem is that ...
0
votes
0
answers
78
views
pybind11 module unable to import Python File in C++
This piece of code is part of one of my wxFrames for a sign up page. I am trying to run some Python code from C++ in order to switch frames, depending on the output of the Python file.
(I use this: ...
2
votes
0
answers
232
views
ImportError: libxxx: cannot open shared object file: No such file or directory [closed]
I am trying to build a Python package that interops with C++ code. I created a PyBind11 wrapper to do the interop. I created a setup.py file following the instructions here:
from pybind11....
1
vote
1
answer
512
views
No Module Named error when trying to run pybind11-stubgen
I've been scratching my head (googling, chatgpt-ing) trying to figure out why I can't generate a pyi file for a pybind module with pybind11-stubgen. I did this about a year ago successfully but can't ...
1
vote
0
answers
37
views
How to clear py::list when clear() does not exist in Pybind11 2.6?
I'm trying to clear a pybind11 list. In version 2.13 of Pybind11, this works great, there's a clear() method that does the following:
void clear() /* py-non-const */ {
if (PyList_SetSlice(...
1
vote
0
answers
88
views
Module has not attribute in pybind11
I am trying to bind c++ program with python using pybind11. The c++ program includes two objects I want to use in my python program, as follows:
#include <pybind11/pybind11.h>
#include "...
0
votes
0
answers
13
views
pybind11: how to export 100 library into one module?
Let's say, I have 100 c++ library, and I want to export to one python module.
Currently, the only method I can find is:
pybind11_add_module(module1 module1Binding.cpp)
pybind11_add_module(module2 ...
0
votes
0
answers
72
views
Python ModuleNotFoundError: No module named 'Binding_py'
I am working on a Python project that uses a C++ extension module created with Pybind11. The C++ project is built with CMake on Jetbrains CLion, and the generated Python extension file is Binding....
0
votes
0
answers
70
views
problems using std::distance function for py::array_t type variable in pybind11
I'd like to get the index of the minimal element of a py::array_t variable in pybind11, but I encountered a problem when trying to combine std::distance and std::min_element.
let's say the py::array_t ...
0
votes
1
answer
160
views
pybind11: how to add document the exported module?
I have some c++ code, and I successfully export it to python module using pybind11. The code is:
class A
{
public:
A()
{
}
/**
* @brief explanation from c++
*/
int ...
0
votes
0
answers
70
views
Subclassing C++ classes in Python with Pybind11 - can I have a virtual method taking kwargs?
in my C++/Pybind11 project I have a C++ class Foo that can be subclassed in Python. As usual, I went through the usual process of having a trampoline class PyFoo and the customary bindings.
However, ...
0
votes
0
answers
113
views
Create python packages with C++ bindings with CMake and Conan
I have a C++ project with some Python bindings created using pybind11. The C++ code has some external dependencies which I fetch using Conan, and I use the conan generated CMake presets to build the ...
0
votes
0
answers
39
views
Python/pybind11 environment
I would like to start a new project using Python and pybind11 and OpenGL on windows. Can you give me some guidance as to how to set up an environment for that? On Linux that would be no problem, but ...
0
votes
0
answers
89
views
Giving C++ sole ownership of class object in pybind11
I have an application in which I want to expose a C++ class MyClass to python using pybind. Since I want python to be embedded within c++, I use PYBIND11_EMBEDDED_MODULE to expose my c++ class.
class ...
0
votes
0
answers
46
views
Unexpected import warning when import a submodule in a .pyd file in VSCode
(
I don't know whether I should tag this question with vscode, because I'm not sure if it is just a VSCode problem, or it's also due to something in python importing or pybind, or even it's just ...
1
vote
0
answers
93
views
std::bad_alloc Error When Passing cv::Mat from C++ to Python via Pybind11 for YOLO Inference
I'm working on a C++ interface to a Python model using Pybind11 and OpenCV. My goal is to read an image using OpenCV in C++ (cv::Mat), pass it to a Python YOLO model (Ultralytics), and retrieve the ...
1
vote
0
answers
118
views
Passing float16 ndarray from Python to C++ with pybind11 results in undefined symbol error
I am attempting to pass a float16 ndarray from Python to C++ using pybind11. While the compilation succeeds, running the Python code results in an error regarding an undefined symbol. Below are the ...
0
votes
0
answers
36
views
How to Expose C++ Qt WebView and Window Functions to Python Without Using PySide or PyQt?
I'm working on a project where I need to integrate a Qt6 WebView into Python. The WebView should allow dynamic control from Python, including:
Setting the window size and style (e.g., resizing, full-...
0
votes
0
answers
100
views
Building pybind11 example successfully, but still got ImportError
I'm trying to use pybind for the first time. I tried different ways, but eventually I decided to go with the 'official' PyBind11 example.
I did the following steps:
install Visual Studio Build Tools ...
2
votes
1
answer
179
views
Overriding C++ class virtual methods in Pybind11 with trampoline class - but still calling base method from C++
I'm implementing a Pybind11 module, and I'm exposing a C++ class to Python that it's meant to be subclassed. I'm following what's described in here (https://pybind11.readthedocs.io/en/stable/advanced/...
2
votes
2
answers
107
views
Passing a python function in a container to a C++ object and pybind wrappers
I am writing a set of Python wrappers via pybind11 for an optimization library whose heavy-lifting code was written in C++.
The abstract class hierarchy of my C++ code to be wrapped currently looks ...
0
votes
1
answer
108
views
PyBind11 produces pyd file without any class i defined
I am working on wrapping a C++ class using Pybind11 to make it accessible in Python. My project involves a dynamic library built with Qt6, which contains a class named Package. I am writing a wrapper ...
1
vote
1
answer
102
views
Why is Hmmlearn giving me a pybind11 GIL state error?
I am trying to use hmmlearn's hidden markov models in my jupyter notebook. No matter how I try to interact with it, I get the same runtime error (which I don't understand and can't find any ...
1
vote
1
answer
105
views
Raising python exception from native thread
I have a C++ class Runner that encapsulates running a native thread. This class is exposed to Python via pybind11, so start_thread is called from Python.
class Runner {
public:
void start_thread() ...
0
votes
1
answer
191
views
Cannot import .pyb / .dll file into Python after compiling C++ code with pybind11 on Windows
My OS is Windows 10, I use G++ compiler, VS Code. I attempt to compile an example pybind11 file into a Python object.
The C++ code looks as follows:
#include <pybind11/pybind11.h>
int add(int i,...