How to embed a Python interpreter in C++ in 10 minutes [Quick Tutorial]

preview_player
Показать описание
This video demonstrates how to embed a Python interpreter in a C++ application using the pybind11 library. Please use the option to pause the video at relevant points to be able to follow the code (many parts of the video have been artificially sped up, this is a "quick tutorial" after all).

00:00 The goal
00:09 CMake project setup in VS
02:02 Install pybind11 using vcpkg
03:31 Executing Python code from Cpp
04:33 Invoking functions from Python scripts from Cpp
05:20 Error handling
06:10 Passing arguments back and forth
06:49 Calling a Cpp function from Python
08:21 Using classes
09:30 Passing arguments by reference
10:24 Outro
Рекомендации по теме
Комментарии
Автор

That is one of the coolest libraries I have ever seen. Was looking for a scripting language for my game engine and this looks perfect. Thank you for this video

quickscopesheep
Автор

Absolutely fantastic tutorial, I need to integrate a python library into a C++ project; and as a bit of a beginner I was a little lost, this has given me exactly what I need to know to get on the right path!

NK-fhst
Автор

Man, this saved my life! Thank you very much!!! <3

legendguitargamer
Автор

This is so much nicer than using LUA :D

mario
Автор

Thank you so much!! This helped a lot!

SushmithaDT
Автор

I do the code from the minute 3:57 and I got the error why can it happening?

Zumito
Автор

I wish the music were lower and the fonts bigger. Though nice video. Thanks.

EnriqueSalceda-kv
Автор

How can we embed, python from a specific path and only using its dll, rather than executable ?
Loved the video, helped me a lot !!!!

blank
Автор

Does it need to have python installed on the machine? Or the .dll already do the interpretation?

AikdeIno
Автор

Thank you for you illustration it was very helpful, although pybind11 was having issues with CMake, but i was resolved, and code was successfully working, but the issue now that, what i we need to run the python code, it will not work as c++ code and function is not know without involving pybind11, so how to make the vice versa, ..I need to search...!! ....[Update] ... I made it 😅

CodePhiles
Автор

I have a question: does He c++ Code make python Code faster? Coz i cant try it now

vulnoryx
Автор

Is there a way to add pybind11 to an existing C++ project? I have an MFC App, and I wanted to write some of the functions in Python, but I am having trouble finding a way to adapt your solution here to my MFC App

IAmTheFuhrminator
Автор

Hi, great video so far,
but I got a Problem. There is an Error in the vcpkg.cmake File:
State
Error CMake Error at (_find_package):
Could not find a package configuration file provided by "pybind11" with any
of the following names:

pybind11Config.cmake
pybind11-config.cmake

Add the installation prefix of "pybind11" to CMAKE_PREFIX_PATH or set
"pybind11_DIR" to a directory containing one of the above files. If
"pybind11" provides a separate development package or SDK, be sure it has
been

I think I followed your steps in the video so far, and I used your VCPGK guide to install vcpkg.
I would be very happy if someone would have an Idea, what I did wrong.
Note, if I install pybind11 as you did in you video, i get an extra Line of code:

The package pybind11:x64-windows-static provides CMake targets:

find_package(pybind11 CONFIG REQUIRED)
# Note: 8 target(s) were omitted.
target_link_libraries(main PRIVATE mylib pybind11::lto pybind11::embed pybind11::module)


I only used :
find_package(pybind11 CONFIG REQUIRED)
target_link_libraries(main PRIVATE mylib pybind11::lto pybind11::embed pybind11::module)

Thanks in advance.

julianf.
Автор

is possible to call a python library like xlwings in my cpp app ?

aymanalmaafi
join shbcf.ru