- The example compiles a Python pyd file that is used by
main.pyto run a function in C++ from Python - Expects Python 3+ and x64 targets
- Python with numpy installed:
pip install numpy - Visual Studio 2022
- premake5
- Windows or MacOS
- MacOS untested, premake-file prepared but might have to be modified.
- see
premake5.luafor how the Python includes and libs are resolved. - run
premake5 vs2022in the terminal to generate the visual studio solution. (premake5 xcode4on Mac) - open
temp/pybind11 tests.sln. - open
pybind_test.cppin the solution projectpython_pydand try to understand how the PYBIND11_MODULE macro works. - build the project (shortcut F7).
- execute
python main_pyd.pyin the terminal inside the python folder. - you can also open
main.cppin the solution projectcpp_mainto run the python interpreter from C++.
The .pyd-file is copied to the same folder as main.py (the root). This means that the module is only available from there. If you want the module to be available globally on your computer, then you have to copy it to one of the default python interpreter search paths.
Relevant threads to read: