This project provides a template to quickly bootstrap Python/C++ projects using PyBind11 for interoperability.
To set up your own PyBind project using this template:
Fork this repository on your preferred Git hosting platform.
When cloning the repository, use the --recursive
flag to ensure the pybind submodule is also downloaded:
git clone --recursive https://<your-fork-url>
While developing locally, you can install the project for testing purposes using these two options:
- Use
pip
:pip install -e .
- Use
setuptools
:python setup.py install
Once your binding is created, you can directly call your APIs from Python. Refer to the test/test.py
file for an example of how to use the generated project structure. To quickly see the current repository in action, you can run:
python test/test.py
This template utilizes Git submodules to manage the pybind dependency. Submodules offer several advantages over manually cloning the dependency into your project:
- Reduced Repository Size: Submodules only store the reference to the dependency, not the actual code.
- Centralized Updates: Updates to the
pybind
submodule are managed independently, ensuring compatibility with your project.
A VSCode launch.json
file can be found in the .vscode
directory of this repository for 2 launch configurations. To enable C++ Debugging in VSCode, open a terminal and export DEBUG_BUILD=1
before proceeding with installation. Example:
export DEBUG_BUILD=1
pip install -e .
This instructs cmake
to build a Debug
version of the library. If not specified, the build system defaults to Release
.
For a deeper understanding of PyBind11 and calling C/C++ from Python, refer to this article:
The article clarifies the steps, explains benefits of submodules, and removes the unnecessary informality.