猿问

安装pybind11时cmake出现问题

我正在尝试按照文档开始使用 pybind11 。我已经使用 pip 安装了 pybind11。该目录的位置是:

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

下一步是编译测试用例。根据文档,我应该运行

mkdir build

cd build

cmake ..

make check -j 4

但是,运行时cmake ..出现错误CMake Error: The source directory "/home/MyUserName/anaconda3/lib/python3.6/site-packages/pybind11" does not appear to contain CMakeLists.txt。所以看来我在pip install 创建的目录CMakeLists.txt中没有该文件。pybind11

知道这里出了什么问题吗?


慕码人2483693
浏览 383回答 2
2回答

湖上湖

当您使用 pip 安装 pybind11 时,您将仅获得结果,而不是 pybind 的源(py 文件、包含文件...)。要运行该示例,您必须检查源代码git clone --recursive https://github.com/pybind/cmake_example.git,然后根据文档运行命令。

叮当猫咪

我正在努力解决同样的问题。但是,我确实开始将 pybind11 作为子模块包含在内。当尝试运行“cmake ..”时,我收到以下错误代码: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.(我正在 Windows 机器上工作,文件夹是 GitHub 的一部分,使用 C++ 的 Hello World 程序可以工作。)从长远来看,尝试运行以下最小代码示例:#include <pybind11>int add(int i, int j) {&nbsp; &nbsp; return i + j;}PYBIND11_MODULE(example, m) {&nbsp; &nbsp; m.doc() = "pybind11 example plugin"; // optional module docstring&nbsp; &nbsp; m.def("add", &add, "A function which adds two numbers");}
随时随地看视频慕课网APP

相关分类

Python
我要回答