pybind11

fatal error: Python.h: no such file or directory

在使用pybind11时,如果不做调整可能就会出现这样的情况,Python.h一般出现在usr/include/pythonx.x文件夹中,而include路径默认情况下只会包含usr/include,所以我们只需要添加include路径即可。

ctrl+shift+p打开C/C++ edit configure,添加如下一行(line:7):

image-20230929141117042

如果你找不到上述文件,那就是你还未安装Python-dev:

sudo apt-get install python3-dev
安装好后,就能在文件夹下看到3.8文件夹了

pybind11的安装:

  1. 将代码下载到本地,使用github加速项目:

    git clone git@gitcode.net:mirrors/pybind/pybind11.git

  2. 提前安装pytest
    pip install pytest python3-dev

cd  pybind11
mkdir build
cd build
cmake ..
make check -j 4 
sudo make install 

使用:

python调用c++利器--pybind11 - 知乎 (zhihu.com)

posted @ 2023-09-29 14:42  石中火本火  阅读(155)  评论(0编辑  收藏  举报