Trouble with cmake when install pybind11

2.9k views Asked by At

I am trying to get started with pybind11, following the documentation. I have installed pybind11 using pip. The location of the directory is:

~/anaconda3/lib/python3.6/site-packages/pybind11

The next step is to compile the test cases. According to the documentation, I should run

mkdir build

cd build

cmake ..

make check -j 4

However, when running cmake .. I get the error CMake Error: The source directory "/home/MyUserName/anaconda3/lib/python3.6/site-packages/pybind11" does not appear to contain CMakeLists.txt. So it seems that I don't have the file CMakeLists.txt in the pybind11 directory that was created by the pip install.

Any idea about what's gone wrong here?

2

There are 2 answers

0
yflelion On BEST ANSWER

When you install pybind11by using pip, you will get only the result and not the source of pybind (the py files, the include files ... ).

To run the example, you have to checkout the sources git clone --recursive https://github.com/pybind/cmake_example.git and then run the commands according to the documentation.

2
TillSeifert On

I am struggling with the same issue. However, I did start to include pybind11 as a submodule. When trying to run "cmake .." I get the following error code:

CMake Error: The source directory "C:/Users/XXXXX/Documents/GitHub/MT" does not appear to contain CMakeLists.txt.
Specify --help for usage, or press the help button on the CMake GUI.

(I am working on a Windows machine, Folder is part of GitHub, Hello World program with C++ works.)

In the long run trying to run the following minimal code example:

#include <pybind11>

int add(int i, int j) {
    return i + j;
}

PYBIND11_MODULE(example, m) {
    m.doc() = "pybind11 example plugin"; // optional module docstring

    m.def("add", &add, "A function which adds two numbers");
}