-2

I am trying to use Pybind11 in a Cmake project. I'm using Cmake 3.23.0-rc2.

To include it, I can do the following:

find_package(pybind11 REQUIRED)

However, this does not work on my machine. So, I attempted to give find_package a hint as per the user guide:

SET(pybind11_DIR, "C:/Users/tyler.shellberg/AppData/Local/Programs/Python/Python37/Lib/site-packages/pybind11")

That did not work either. The Cmake error suggested it may need to be the specific location of files like pybind11Config.cmake. So, I tried being more specific:

SET(pybind11_DIR, "C:/Users/tyler.shellberg/AppData/Local/Programs/Python/Python37/Lib/site-packages/pybind11/share/cmake/pybind11")

That doesn't work either. I get the exact same error in Cmake:

CMake Error at lib/(our project name)/CMakeLists.txt:30 (find_package):
  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

  Add the installation prefix of "pybind11" to CMAKE_PREFIX_PATH or set
  "pybind11_DIR" to a directory containing one of the above files.  If
  "pybind11" provides a separate development package or SDK, be sure it has
  been installed.

I double checked, Python itself is being found:

Python_FOUND:TRUE
Python_VERSION:3.7.4
Python_Development_FOUND:TRUE
Python_LIBRARIES:C:/Users/tyler.shellberg/AppData/Local/Programs/Python/Python37/libs/python37.lib
Python_INCLUDE_DIRS:

(Though weirdly, include_dirs is empty)

What am I doing wrong?

Tyler Shellberg
  • 1,086
  • 11
  • 28

2 Answers2

2

One way is to find Python3 first and then use the sitelib as a hint:

find_package(Python3 REQUIRED)
find_package(pybind11 REQUIRED HINTS "${Python3_SITELIB}")
Alex Reinking
  • 16,724
  • 5
  • 52
  • 86
  • find_package(Python3) doesn't populate variables like Python_FOUND, Python_VERSION, etc. That's why I swapped back to using find_package(Python) instead. – Tyler Shellberg Nov 07 '22 at 15:35
  • 1
    @TylerShellberg - It populates `Python3_FOUND` and `Python3_VERSION`... – Alex Reinking Nov 07 '22 at 18:54
  • Thanks, that seems to work OK. Can't re-test as I already installed the [global] version of Pybind11, but it may be useful to others who run into this. – Tyler Shellberg Nov 07 '22 at 18:57
1

pip install "pybind11[global]" fixed it. It may not be recommended, but it works. Found the recommendation from here: How to make cmake find pybind11

Tyler Shellberg
  • 1,086
  • 11
  • 28