Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make cmake find pybind11

I am trying to follow the simple example for embedding python within c++ using pybind11 as found on this page. However, when trying to use cmake to build the solution, I keep getting an error that says

By not providing "Findpybind11.cmake" in CMAKE_MODULE_PATH this project has asked CMake to find a package configuration file provided by "pybind11", but CMake did not find one.

Could not find a package configuration file provided by "pybind11" with any of the following names:

pybind11Config.cmake
pybind11-config.cmake

I have a folder called pybindtest on my Desktop which includes CMakeLists.txt and main.cpp as described in the link above, as well as a build folder that I created. While in the build folder, I have tried the following lines to no avail (running on Powershell 7):

cmake ..
cmake .. -Dpybind11_DIR=C:/Users/ben.wolfley/Anaconda3/Library/share/cmake/pybind11/pybind11Config.cmake
cmake .. -DCMAKE_MODULE_PATH=C:/Users/ben.wolfley/Anaconda3/Library/share/cmake/pybind11

I installed pybind11 using conda install pybind11, and pybind11Config.cmake is in C:\Users\ben.wolfley\Anaconda3\Library\share\cmake\pybind11

like image 478
bwolf Avatar asked Dec 07 '25 02:12

bwolf


1 Answers

In case someone having the same issue without Anaconda, like directly with pip pybind11 or manual clone installation, both caused problems in my case. Manual installation of pybind11 with git didn't install the cmake config pybind11Config.cmake, although there is a tools/pybind11Config.cmake.in file, that I couldn't turn into a proper pybind11Config.cmake.

Installation pybind11 global with pip solved it for me, and automatically uninstalled the manual git installation:

pip install "pybind11[global]"

which installed both pybind11 and pybind11-global with proper cmake config like Anaconda does.

like image 86
KeitelDOG Avatar answered Dec 08 '25 18:12

KeitelDOG



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!