在 C++ 项目中使用 Pybind11

安装 pybind11:

pip install 'pybind11[global]'
# add your executable
set(PYTHON_EXECUTABLE /opt/miniforge3/bin/python)
find_package(pybind11 REQUIRED)
target_link_libraries(your_executable PRIVATE pybind11::pybind11 pybind11::embed)

设置 PYTHON_EXECUTABLE 可以确保 pybind11 使用正确的 python 版本,这样才能在里面找到你安装好的其他的包。