Pybind11: couldnt find pybind11Config.cmake

Created on 25 Apr 2018  路  28Comments  路  Source: pybind/pybind11

I have installed pybind using pip install pybind11 and using python 3.6 and cmake 3.5.

_CMakeLists.txt:_

cmake_minimum_required (VERSION 3.5)
project(dummy_proj)
find_package(pybind11 REQUIRED)
pybind11_add_module(test test.cpp)

_Running cmake . gives an error:_

CMake Error at CMakeLists.txt:4 (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.

Can anyone tell me how to complie it?

Most helpful comment

There is definitely a documentation issue here. After reading some stackexchange stuff, I realized the best way to install pybind11 is by conda, which was easy and solved the issue of the missing cmake file. But why isn't this (how to install pybind11) the first thing you see here: https://pybind11.readthedocs.io/en/stable/basics.html
I shouldn't have to google around to figure out the proper install procedure. The docs front goes straight to "Compiling test cases", but skips a discussion of the recommended install procedure. This is causing confusion because some people are using pip to install but this does not install some of the files (like cmake file). "First Steps" really means "First Steps After Installation". This is a sin of omission.

All 28 comments

I'm not wholly sure that a pip install pybind installs pybind11Config.cmake and other needed files. (I do know that the latest conda install pybind11 -c conda-forge does.) If, after your pip install, you confirm that <install-dir>/share/cmake/pybind11/pybind11Config.cmake exists (in which case ignore my first two sentences), you can instruct cmake to find it via cmake -Dpybind11_DIR=<install-dir>/share/cmake/pybind11. Hope that helps.

I searched for pybind11Config.cmake in my system, but couldn't find any. It only installs the header files. I saw a talk from Ivan Smirnov where he mentioned installing with pip and using cmake. Conda install works. Thanks.

A mention that I just ran into this issue too.

@rob-smallshire check this out - https://github.com/sdhnshu/pybind_demo

hit the same problem

Would it be possible to include the pybind11Config.cmake in the Python wheel? I was expecting that the wheel contains everything that is needed which would be header + the cmake config script...

I have the same issue when using appveyor to build projects using pybind11. It would be nice to have pybind installed via pip rather than having to download the source configure and install it.

There is definitely a documentation issue here. After reading some stackexchange stuff, I realized the best way to install pybind11 is by conda, which was easy and solved the issue of the missing cmake file. But why isn't this (how to install pybind11) the first thing you see here: https://pybind11.readthedocs.io/en/stable/basics.html
I shouldn't have to google around to figure out the proper install procedure. The docs front goes straight to "Compiling test cases", but skips a discussion of the recommended install procedure. This is causing confusion because some people are using pip to install but this does not install some of the files (like cmake file). "First Steps" really means "First Steps After Installation". This is a sin of omission.

I am working on arm and it's a bitch to install new versions of conda here. I tried to clone and make - I don't see any folder named share? I do see pybind11Config.cmake in pybind11/build but when I link to it ( export pybind11_DIR to the build folder) I get a different error when making the program i"m actually interested in ( caffe2 ).

CMake Error at /root/pybind11/build/pybind11Config.cmake:100 (include):
include could not find load file:
pybind11Tools

This file does exist in pybind11/tools which makes me think that I'm not linking appropriately.

Is there a way to properly install without conda?

Thanks in advance, Dan

I'm not wholly sure that a pip install pybind installs pybind11Config.cmake and other needed files. (I do know that the latest conda install pybind11 -c conda-forge does.) If, after your pip install, you confirm that <install-dir>/share/cmake/pybind11/pybind11Config.cmake exists (in which case ignore my first two sentences), you can instruct cmake to find it via cmake -Dpybind11_DIR=<install-dir>/share/cmake/pybind11. Hope that helps.

I don't need help with this anymore, but my question may still be relevant for others so i'll leave it up here.

The solution above is not completely solving it for me. I removed the pip version, and installed the conda version. I added

-Dpybind11_DIR=/home/james/anaconda3/envs/mycondaenv/share/cmake/pybind11

and my CMakeLists.txt file is

```cmake_minimum_required(VERSION 3.10)
project(pybind_learning_try2)

set(CMAKE_CXX_STANDARD 11)

find_package(pybind11 REQUIRED)
pybind11_add_module(Vehicle Vehicle_pb.cpp)

add_executable(pybind_learning_try2 main.cpp example.cpp example_pb.cpp Vehicle.cpp Vehicle.h Vehicle_pb.cpp util.cpp util.h Truck.cpp Truck.h)
```

Now the cmake project loads correctly (in my CLion IDE), no longer giving the error _...Could not find a package configuration file provided by "pybind11"..._, but the line

#include <pybind11/pybind11.h> in my .cpp file now fails to compile with

fatal error: pybind11/pybind11.h: No such file or directory #include <pybind11/pybind11.h>

I can still compile correctly in the command line in my virtual environment with

c++ -O3 -Wall -shared -std=c++11 -fPIC `python3 -m pybind11 --includes` Vehicle_pb.cpp util.cpp -o Vehicle`python3-config --extension-suffix`

Apologies if the solution is trivial, thank you in advance for the help.

EDIT: The solution:
CLion->settings->Build, Ex..->CMake->CMake options: add (without quotes)
"-Dpybind11_DIR=/home/james/anaconda3/envs/mycondaenv/share/cmake/pybind11"

Then your CMakeLists.txt will look something like:

cmake_minimum_required(VERSION 3.10)
project(pybind_learning_try2)

set(CMAKE_CXX_STANDARD 11)

find_package(pybind11 REQUIRED)
include_directories(${pybind11_INCLUDE_DIR})
pybind11_add_module(...)

add_executable(...)

where the ... represent things you need to fill in.

If possible, please, re-open. There is still no way to install this library without conda, e.g. as a dependency, because the file pybind11Config.cmake is absent. See for instance https://github.com/onnx/onnx/issues/1624 as well as https://github.com/pybind/pybind11/issues/1628 and https://github.com/pybind/pybind11/issues/1733

Now the cmake project loads correctly (in my CLion IDE), no longer giving the error ...Could not find a package configuration file provided by "pybind11"..., but the line

#include <pybind11/pybind11.h> in my .cpp file now fails to compile with

fatal error: pybind11/pybind11.h: No such file or directory #include <pybind11/pybind11.h>

I can still compile correctly in the command line in my virtual environment with

c++ -O3 -Wall -shared -std=c++11 -fPIC `python3 -m pybind11 --includes` Vehicle_pb.cpp util.cpp -o Vehicle`python3-config --extension-suffix`

Same issue here, I still cannot resolve the header pybind11.h in Clion. Your fix can solve the CMake problem, but not Clion resolving the header.

Isn't this problem as simple as adding a pybind11Config.cmake into the 'pybind11-dev' ubuntu/pip packages? Or just adding it into the repository? I'm not sure how those packages manager's are updated (Do they feed right in from the github?)

I don't think this should be closed until a pybind11Config.cmake is added to pip and the ubuntu packages. I shouldn't have to exclusively use conda in order to use cmake with pybind.

In the installation procedure of FEniCS, a pde numerical calculation suite, the trouble is fixed by installing the pybind just by cmake. You may need it to serve as a workaround when the official cmake configure absent.
FEniCS Installation

installing pybind11 via conda is the only straight forward solution so far.

I'm trying to use onnx-runtime on a machine where conda is not an option because a third party windows 32bits software required for the project can only handle pip.

I go the same pybind error message.

Does any one have way of installing pybind with pip only ?
Or does any one have way of installing onnx-runtime with pip only ?

Error disappeared when downgrading python to python3.7.

As mention in https://github.com/onnx/onnx/issues/2734 , onnx does not support python3.8 for the moment. pip install onnx produces the same error as pip install onnxruntime on my Ubuntu 18.04 LTS machine when using python3.8.

Onnx v1.7.0 released today is compatible with python 3.8 . With this new version of onnx, I did not get the pybind11Config.cmake error when installing onnxruntime

@rob-smallshire check this out - https://github.com/sdhnshu/pybind_demo

Hi, the link is broken.

I was able to fix the problem by installing the python3-pybind11.

apt-get install python-pybind11

I was able to fix the problem by installing the python3-pybind11.

apt-get install python-pybind11

That's probably going to be a horribly old version of pybind11, though?

+1 it's december 2020 now and we're also running into this issue

+1 about what? The PyPI wheels should work, now, no?

I was able to fix the problem by installing the python3-pybind11.
apt-get install python-pybind11

That's probably going to be a horribly old version of pybind11, though?

It definitely is...

The pip wheel install the cmake in: $USER/.local/lib/python3.6/site-packages/pybind11/share/cmake/pybind11/
Which is not a standard from cmake if I recall...
How to get access to this install?

How to get access to this install?

I can't explain it better than @henryiii in the docs: https://pybind11.readthedocs.io/en/stable/installing.html & https://pybind11.readthedocs.io/en/stable/compiling.html
I guess one way would be to use pybind11.get_cmake_dir() and add it to your CMake path, but the docs explain more.

You might want the global option pip install pybind11[global] if you want a standard location for the files.

Just to clarify, this has been fixed and is supported since 2.6.0, and the docs should cover it clearly. If there still is a problem, open a new issue. Any problems here were due to the fact our CMake didn't support this, and we didn't distribute CMake files. Any new problems should be a new issue so they can be resolved - we can't resolve and close a 2-year old issue that's already resolved and closed.

Was this page helpful?
0 / 5 - 0 ratings