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:

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):

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


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/ 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:

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


How to make cmake find pybind11 by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply