aoloe / cpp-pybind11-playground

Creating a Scripting Egnine with pybind11. Step by step. https://github.com/pybind/pybind11
35 stars 9 forks source link

pybind11 as a scripting engine

This tutorial explains in 14 steps how to use pybind11 for creating a Python scripting engine for a Qt application.

It first explains how to create a module that can be imported in Python, continues by prosenting different aspects of running inside of a C++ (Qt) application a Python script that can access (and modify) the status of the main application.

Each step contains code that can be individually compiled, run, and – of course – modified.

You should probably go through each step in the order presented below, since the commands are (briefly) introduced only once.

Getting pybind11

There are three ways for getting pybind11:

The samples in this repositories use a pre-compiled version of pybind11. If you're not getting pybind11 from your distribution repositories:

The pybind11 authors prefer adding pybind11 as a git sub-project: you can of course follow their instruction and adapt the CMakeLists.txt files in this repository.

The development environment

You need:

Our first example directly uses the compiler, all other examples will need a modern version of cmake being installed (pybind11 needs cmake 3.4)

Sample projects

Links

Notes

alternatives

todo

Document all directories:

open questions: