随笔分类 -  python / pybind11

摘要:一、创建解释器 需要在使用任意Python API前初始化解释器,包括pybind11 Python函数和类。RAII guard类`scoped_interpreter`可用来管理解释器的生命周期。在guard类销毁时,解释器将会关闭并占用的内存。必须在所有Python函数前调用它。 #inclu 阅读全文
posted @ 2023-06-24 21:58 夏蝉沐雪 阅读(1011) 评论(0) 推荐(0) 编辑
摘要:一、自定义数据结构-结构体 `class_`会创建C++ class或 struct的绑定。`init()`方法使用类构造函数的参数类型作为模板参数,并包装相应的构造函数;静态成员函数需要使用`class_::def_static`来绑定 #include <pybind11/pybind11.h> 阅读全文
posted @ 2023-06-24 17:04 夏蝉沐雪 阅读(2033) 评论(0) 推荐(0) 编辑
摘要:1、头文件和命名空间约定 #include <pybind11/pybind11.h> namespace py = pybind11; 2、函数绑定 `PYBIND11_MODULE`会创建一个函数,它在Python中使用`import`语句时被调用。宏的第一个参数是模块名(example),不使 阅读全文
posted @ 2023-06-17 11:30 夏蝉沐雪 阅读(1868) 评论(0) 推荐(0) 编辑
摘要:一、安装pybind11 方法1,直接用pip安装:pip3 install pybind11 方法2,源代码安装:git clone https://github.com/pybind/pybind11 二、VS2019配置pybind11及使用 这里只讲解windows + vs + pytho 阅读全文
posted @ 2023-06-15 16:11 夏蝉沐雪 阅读(1095) 评论(0) 推荐(1) 编辑

点击右上角即可分享
微信分享提示