1:56 Me noticing the missing semicolon before he compiles while understanding very little about everything else: "Sometimes my genius is almost frightening"
I usually watch videos in x2 speed, however here I had to put it in 0.5x speed 🤣 I'm discovering both C++ and pybind11 so although it is hard to follow everything yet your explanation is pretty cool as it sums up most of the functionalities available in a short time, I now understand better where I need to start ! thank you
Found your channel a few days ago, and absolutely loving your intuitive example-based explanations. It's also great that when you start covering a topic you stick to the essentials - it's short, to the point, and incredibly helpful when getting started!
Subscribed! I love that you zoom in as necessary, which makes it perfect to watch on my smartphone... that you provide the source code much as possible... that you speak very clearly... that you actually communicate great with your many fans... and let us know what other alternatives there are for those of us not familiar with other modules.
I have to write a python program to run this video at half speed. Either that or pause it ever 5 seconds. Lots of information packed into a few minutes.
Stumbling on this video while researching this topic, I was initially disappointed to see, that it was only 10 minutes long but holy crap this is jam packed with info. Thanks a bunch!
Great video once again. I like your speed of presentation - I usually watch tutorial or showcase videos with 1.5x speed (sometimes even 2.0x, ugh) because I detest long, drawn out sentences and vacuous rhetoric. I actually had to check whether my playback speed was still up, hahaha. Nice job!
I just want to comment that i loved this video! It's the first time a video has helped me more than any written tutorials/docs I could find, I struggled for a day before I came across this! As a side note - I would love if you had posted the whole file-structure and a note on the dependencies, I struggled a bit before figuring out that pybind11.h needs to include Python.h and related files. I feel like that is a point practically all tutorials on pybind11 are missing, hence why I haven't gotten any of them to work for me :P
@@mariam.magued24 I got it working shortly after posting this, and first of all I want to say: Pybind11 is a GODSEND. Once you figure it out it just works amazingly. It is definitely worth the couple of days you might have to spend before you get everything to work smoothly. To address the issue: You have to figure out how to download/install the python developer files for your system. For Linux it's something like "apt-get install python-dev". For macOS (darwin) it's something like "brew install python-dev". Then you have to make sure that pybind11 finds the correct python-files on your PATH. Uninstalling old versions of python that you have lying around may help.
@vegardjerven I am currently struggling too, but not only a little bit but a lot. How did you solve your problems and how did you find that out, that Python.h has to be included in pybind11.h? My main problem is actually that I get this error: Python libraries not found. Can you maybe help me with that and tell me what you did to get everything going? I know you probably have better things to do than help a random kid on the internet, but I would really appreciate any help. Maybe you can recommend a good tutorial on YT or google which helped you solve your problems. Thanks in Advance!
@@alexkonopatski429 Hey! I'm happy to help as much as I can :) the first issue is that I haven't found any tutorial on that part of getting pybind to work, it seems like the kind of thing everybody just "expects you to know"... The second thing I want to say is: Don't give up! Pybind11 is worth every second you put into getting it working the first time. After that it's smooth sailing. With that said: You first have to download and install "python with developer files". The easiest thing to do, might be to uninstall any and all python installations on your system (be careful if you have linux). Then google "install python with headers" or "install python developer" or something like that, and install python with the headers (Sorry, I can't help you more without knowing what system you're on etc.). Once you have those, you can point pybind11 to your python executable with "set(PYTHON_EXECUTABLE )" in your CMakeLists.txt file. You can also try adding the python include directory to your projects include path using target_include_directories (cmake.org/cmake/help/latest/command/target_include_directories.html#command:target_include_directories) after the call to pybind11_add_module. If you get that right, pybind11 should be able to find the headers it needs. Best of luck!
Hey nice video. Pybind is really simpler than other methods i used before. i shared with some friends thst might find it useful. if I may, I would give just a little small feedback on the video itself. i really like the fast paced style but would it be possible to let a second of code in the screen so it makes easier to pause and read? sometimes after the last char of the code is completed screens change and makes watching in mobile is little harder great video and nice explanation!!!!
@@JackofSome actually I love it's fast. many people are just to slow and kept in the bare basics to kick out like 10 videos of just too basic stuff just need a little second there just to click the pause button :)
@@JackofSome I really liked the speed in this video, it was perfect. I do agree with OP that simply leaving the code on screen for an extra second would be very helpful though.
Having to redefine what functions in a class to expose seems very unnecessary when the original c++ code will already have defined what is public and private.
I find myself treating what's public/private differently than what's kosher for a python interface, since more considerations go into that (e.g. object lifetime concerns), so I personally like that it's this way. I think I did see a macro once that automated some parts of it.
Often what you want to be public and private in code may be different to what you want to expose. For example using helper classes/structs and such in your code.
I really liked this video. You immediately answered the two questions I had after messing around for a couple of hours trying to wrap a quite complicated algorithm today. I have one suggestion for improvement. While you talked a bit fast for me to follow I could slow down the video. However, some of the code after you finish writing and some prints when running are difficult to see. I would like to have at least a few frames with the final result. For example I don't think the final line with gil_scoped_acquire was completely there... Liked it a lot though, I will check out more of your content!
I have a silly question. If cmake uses the clang compiler instead, would this be a problem? I have seen some people doing this online. However, if Python is building modules it would use the gcc or msvc compiler by default, i.e. the compiler used to make the python distribution.
Unrelate question: I'm looking for a way to compile python scripts into executables. It's not py2exe and it's not pyinstaller. I came across the site a few weeks ago, but i cannot remember the name of it, and i can't find it in my history. A google search doesn't help. I think i may have heard about it on this channel, which is why i'm asking here.
@@dariusravn9982 Looks cool, but it wasn't it. Your hint did lead me to the correct one: Nuitka. Thanks! Now i don't know if that's any good, but i wanted to try it. And then i lost the site :D
Hey, great video, it is a nice intro to pybind11, i have a 2 questions, a pybind11_module is a seperate c++ file right, say i am embedding along with extending python, how do I let the c++ module know of the resources in the main executable? Second question, vsc just bugs out while i am trying to call the functions in the module, do you have any idea how to fix the intellesence ?
The C++ resources get garbage collected like any other Python object unless you make special changes to their lifetime management. No idea how to fix the intellisense, sorry :(
I got a question. How do I make regular multidimensional array (ex. static int array[100][100][10] ) to return as a numpy array? What if I just have a pointer to this array (which I created using typedef)? I like to avoid any copying, if possible. Hope I get a reply soon. Thanks in advance!
I don't know what cmake is. I researched a little and have two Qs: 1) should I pip install cmake? Is there a better way? 2) Is our cmake file .cmake? Is that a file I create?
Useful tutorial, though I when I follow the absolute minimal example, I get the error "ImportError: dynamic module does not define module export function (PyInit_pybind_test)"
Hi, thank you for the nice and recent tutorials! I was having trouble running an existing git that binds c++ module. When I try same thing as 2:33, it gives me ImportError: dynamic module does not define module export function (PyInit_shot
I had this issue. The name of the module in main.cpp MUST be the same as the target name in CMakeLists.txt. When you have "PYBIND11_MODULE(name1, m)" in main.cpp and "pybind11_add_module(name2 main.cpp)" in CMakeLists.txt, name1 must be the same as name2. name2 will be the name of the so file generated, which python will look for the module name. So you can do "import name2" and python will identify name2 as the name of a python module. But name1 will be the module that is actually defined inside the so file. But if you try "import name1", python won't be able to find the name1 module.
It's not fully public, but a version of it is here github.com/safijari/stupid-spacemacs It's basically my own take on a spacemacs/doom emacs style kit.
@@JackofSome that makes sense. I think the people who say "dire" pronounce directory as "dire-rec-tory" but the people who say "der" pronounce directory as "der-rec-tory".
This is a genuine question. Considering standard Python is so much slower than C / C++ and newer compiled languages like D and Nim are just about as easy as Python with the added benefit of being compiled and pretty much as fast as C / C++, why is Python so popular and used so much?
Legacy. If I were to move my code base to another language it would take a team twice the size of my own (my team is really small) at least a year to make the transition.
@@JackofSome also availability of libraries. No one wants to write things over and over again and python simply has many many libraries while having "good enough" performance. If a developer cares about speed, c++ or rust may even be better!
@@JackofSome True, but I personally don't feel like "legacy code" is the top reason why python is pervasive. I think people really enjoy writing in python in a way that, imo, no other language has captured. That user experience is what caused the scientific computing community to move their work over to python during the 2000-2010's, which is what opened up python to being the most important language for ML, and why there's so many utilities surrounding that field for CV/NLP/etc. (Also, I think the "python is slow" mantra is overblown, but that's another discussion, lol.) btw, I love your video! This was very interesting and informative, and I know that I'd love some follow up videos if you're interested!
@@JackofSome it did have errors, which I fixed. But then the make couldn't be completed because python was giving quite a few errors, the solution to which I haven't found yet. Although I'm on Windows and I'm having a lot of trouble with this. Nearly every major module for integrating C++ and Python is primarily for Linux and I unfortunately can't install Linux as of yet. Anyway, thank you for your time! I'll refer to your video again when I'm actually on Linux, which will hopefully be in a month or two!
Ok i fixed it by deleting the module_name.cpython... that cmake was making, and replacing with mine after running '$ c++ -O3 -Wall -shared -std=c++11 -fPIC $(python3 -m pybind11 --includes) ../main.cpp -o main$(python3-config --extension-suffix)' from pybind11.readthedocs.io/en/stable/basics.html
Im currently learning C to make my own programming language, I'm calling it "Vide", can you tell the basics of a programming language, if you know what the basics are?
Your video is interesting and clear, but I downvoted it because it's way too fast. It's even kind of hard to pause the video at the right moment to read the code. I know I can slow the playback speed, but that's just a workaround
That's perfectly fair. Like I said in the video if my aim is to just speed up a bunch of code I usually turn to Numba. Pybind11 is great for those cases where I have to use C++, for any number of reasons.
This is not a tutorial in any form. It would easier to find a piece of code similar to that and read it than listening to this guy pre-record code and debugging process while flying through it. Please do not share :)
I guess your counting is as good as the quality of your video. You don’t even have 40000 views. You only have 1.1k likes. Don’t argue with me. I am telling you, the quality of your tutorial sucks. You wanna know how you should teach a programming piece? Watch one video from Corey Schafer's Python videos. You wanna watch how to produce a nice instructional (non-coding) video, watch ChrisFix. Then come back and redo this please. Thanks
Installation is cloning the repo, setup is making the cmakelists file (integration to setup.py and deployment specifics will be another video). Both are covered here.
@@JackofSome one more question. With the example you have in the video. What would be the cmake file. For example, what would CMakeLists.txt look like for you? Thank you.