#include <pybind11/pybind11.h> 报错
VScode C++调用pybind11出现include报错
首先确保已在虚拟环境中下载了 pybind11 ,如果没有,则在要使用的环境中使用 pip install pybind11
要做的就是修改c_cpp_properties.json
该文件可以通过:报错的地方 -> 快速修复 -> 修改include路径 生成
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**",
"d:/Anaconda3/envs/pyml/lib/site-packages/pybind11/include",
"D:/Anaconda3/envs/pyml/include"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "D:\\mingw64\\bin\\gcc.exe",
"cStandard": "c17",
"cppStandard": "gnu++17",
"intelliSenseMode": "windows-gcc-x64"
}
],
"version": 4
}
要添加的是
"includePath": [
"${workspaceFolder}/**",
"d:/Anaconda3/envs/pyml/lib/site-packages/pybind11/include",
"D:/Anaconda3/envs/pyml/include"
],
中的 d:/Anaconda3/envs/pyml/lib/site-packages/pybind11/include 和 D:/Anaconda3/envs/pyml/include
前者可以在vscode中打开一个python文件,并且保证使用的环境是下载了 pybind11 的
然后运行代码
import pybind11
print(pybind11.get_include())
conda activate pyml
python -c "import sys; print(sys.prefix + '\\include')"
后者在 Anaconda prompt 中运行
conda activate pyml
python -c "import sys; print(sys.prefix + '\\include')"

浙公网安备 33010602011771号