pybind11

How do I import a .pyd module written in C++ to Python using PyBind11

How do I import a .pyd module written in C++ to Python using PyBind11 Question: I am working on Windows 10 with Python 3.9.7 and have anaconda setup on my laptop. I have compiled a C++ code calcSim.cpp where the module name is calJaccSimm and am able to successfully generate a .pyd file with the …

Total answers: 1

pybind11 cannot import templates

pybind11 cannot import templates Question: I tried to use templates in pybind11 based on this demo. Error >>> from example import add >>> add(2,3) 5L >>> from example import myadd Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: cannot import name myadd Why does myadd cannot be imported while add can? …

Total answers: 1

Why don't you need to do target_link_libraries when using Eigen with pybind11

Why don't you need to do target_link_libraries when using Eigen with pybind11 Question: I was trying to compile this example.cpp from a pybind11 tutorial called pybind11_examples on GitHub #include <pybind11/pybind11.h> #include <pybind11/eigen.h> #include <Eigen/LU> #include <iostream> // —————- // regular C++ code // —————- Eigen::MatrixXd mul(const Eigen::MatrixXd &xs, double fac) { std::cout << "Double" << …

Total answers: 2

Pybind11 – ImportError: …/pybindx.cpython-38-x86_64-linux-gnu.so: undefined symbol: _ZN6google8protobuf8internal26fixed_address_empty_stringB5cxx11E

Pybind11 – ImportError: …/pybindx.cpython-38-x86_64-linux-gnu.so: undefined symbol: _ZN6google8protobuf8internal26fixed_address_empty_stringB5cxx11E Question: I wrote some binding code to bind C++ code with python in pybindx.cpp file. I want to call some functions (implemented in C++) using python. When I use python setup.py build_ext command, the .so file ./build/lib.linux-x86_64-3.8/pybindx.cpython-38-x86_64-linux-gnu.so is getting created, but when I try to import(import pybindx) in …

Total answers: 1

Why does lldb only show "dyld" in each stack frame on macOS Ventura?

Why does lldb only show "dyld" in each stack frame on macOS Ventura? Question: I maintain a Python library that’s written in C++ (using Pybind11). For the past couple of years, I’ve been able to debug it just fine with lldb, just by compiling the extension in debug mode (i.e.: disabling optimization and including symbols, …

Total answers: 1

PyBind11: How to implement Vector of Shared Pointers of Classes with Inheritence? Unable to load a custom holder type from a default-holder instance

PyBind11: How to implement Vector of Shared Pointers of Classes with Inheritence? Unable to load a custom holder type from a default-holder instance Question: I have a base class in c++ that looks like: class EdgeAttributePipelineStep { public: virtual void setAttributes(Edge& edge) = 0; }; And then some classes that inherit from this class: class …

Total answers: 1

pybind11 module dependencies macOS

pybind11 module import or link .so dependencies macOS Question: TLDR: How do I link a .so/import a dependency when importing my pybind11 module in python? I am attempting to build a pybind11 module that, in parts, depends on the C++ part of a different python library. On Linux, I can just link that library in …

Total answers: 1

pybind11: convert py::list to std::vector<std::string>

pybind11: convert py::list to std::vector<std::string> Question: I have the following sample code which obtains a py::list as the output of evaluating some python code. I would like to convert it to a std::vector<std::string>, but am getting an error: conversion from ‘pybind11::list’ to non-scalar type ‘std::vector<std::__cxx11::basic_string<char> >’ requested Per the documentation: When including the additional header …

Total answers: 1

Why does pybind fail for functions without arguments?

Why does pybind fail for functions without arguments? Question: I have an overloaded constructor in C++ (default + other). My automatically generated pybind code looks like this: py::class_<MyClass>(m, "MyClass") .def( py::init<>(), py::kw_only() ) .def( py::init< std::valarray<std::string> >(), py::kw_only(), py::arg("my_var") ) When I delete the first constructor everything works fine. But for the first one I …

Total answers: 1

/usr/include Directory on WSL

/usr/include Directory on WSL Question: I am using WSL on Windows and in the directory /usr/include I have a subdirectory called python3.8. As I understood the /usr/include includes the header files for C compilers. I have installed python3.10 but it seems that python3.8 exists by default in WSL. Hence, I am having some conflicts with …

Total answers: 1