-2

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?

Ðаn
  • 10,934
  • 11
  • 59
  • 95

2 Answers2

1

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.

yflelion
  • 1,698
  • 2
  • 5
  • 16
0

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");
}
  • This does not really answer the question. If you have a different question, you can ask it by clicking [Ask Question](https://stackoverflow.com/questions/ask). To get notified when this question gets new answers, you can [follow this question](https://meta.stackexchange.com/q/345661). Once you have enough [reputation](https://stackoverflow.com/help/whats-reputation), you can also [add a bounty](https://stackoverflow.com/help/privileges/set-bounties) to draw more attention to this question. - [From Review](/review/late-answers/30672365) – betelgeuse Dec 27 '21 at 08:55
  • Thank you. Yes, I wanted to extend the question. Sorry about the inconvenience. I created a new question now here: https://stackoverflow.com/questions/70495267/getting-started-with-pybind11-and-cmake – TillSeifert Dec 27 '21 at 12:07