Standalone Python EXE Executable - Python Kivy GUI Tutorial #20

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
what's going on guys john elder here from coding.com and in this video we're going to take our calculator and turn it into a standalone executable file with kivy and python all right guys like i said in this video we're going to turn our calculator app into a standalone exe file for windows and mac but before we get started if you like this video you want to see more like it be sure to smash the like button below subscribe to that channel give me a thumbs up for the youtube algorithm and check out codeme.com we have dozens of courses with hundreds of videos that teach you to code use coupon code youtube1 to get 30 membership that's all my courses videos and books for one time fee is just 49. which is insanely cheap okay so in the last few videos we've been building out this simple calculator app in this video we want to sort of package it all up into a standalone executable file for windows and mac now i know a lot of you guys want to do this for android and we'll talk about that later in this video we're going to look at windows and mac sort of the first step so there's a way to package all of this into one exe file we're not going to look at that in this video it's a little bit more complicated we may look at that later in this video we're just going to create a the big package it's going to have many files we're going to zip it all up into one file that you can then share with people or whatever and that's sort of the basic way to do it so let's go ahead and close this now we're not actually going to make any changes to our code so far except i'm going to move it from the current directory into another directory just to separate it from all the other stuff we've been working on up until now so i'm going to pull up a file explorer and i'm just going to go to our c drive and then find the directory we've been working and kivy gui and you can see here is calc.kv and calc.pi i'm just going to right click i'm going to highlight them both right click and click copy and then i'm going to come up here and i'm going to create a new folder and let's just call this calc or calc calc is fine so it really doesn't matter what it's called so let's open this and i'm going to right click and paste in our two files that we've been working on so okay let's now pull up our git bash terminal okay so we've got the get bash terminal now make sure you've got your virtual environment turned on and you can tell that because it says vert there if you don't know what i'm talking about we set up a virtual environment way back at the beginning of this playlist you can check a link in the comment section below for the playlist for this kb playlist and check that out but make sure your virtual environment is turned on because we're going to install something now that will take care of all this stuff for us it's going to package up our file into an exe and executable file so to do that let's go pip install and this is pi installer now i've already got it so you know it's telling me i've already got it it will install on your computer and you should be good to go now you can confirm that if you want by typing pip freeze and you can see here's the pi and saw installer stuff that's been installed here's all our kibby stuff and some other stuff we've installed along the way so okay now let's move into that new directory we just created so i'm gonna go cd and let's go calc okay and you can see now we're in this calc directory and if i type ls you can see here's our two files that we just moved in there okay so to package up our file this is going to take several steps it's going to take a little while the first step is to type pi installer and the name of our main python file calc dot pi and then we also want dot w otherwise this will create a blank like dos screen every time we run our program we don't want that so this is all we have to do to do this on windows now if you're on a mac the only difference is you need to type dash dash one file right so if you're on a mac do it like this if you're on windows do it like this now i'm on windows so from here on out we're just to do this on windows but it's basically the same for mac shouldn't have much problem so this is going to go through here and it's going to grab it's going to grab our python file calc.pi and it's going to do all kinds of stuff it's going to create all kinds of different files and directories and it's just a bunch of stuff and so we just sort of sit back and wait for it to do its thing shouldn't take but a minute or two okay so that just took a few seconds so now we can come back over to our directory here that we just created here's our calc directory in our kivi gui directory and you can see now there's all kinds of other stuff right and the thing we care about now is this calc.spec file we need to make some changes quite a few bit quite a few changes to this calc.spec file and the first thing you want to sort of realize is we just packaged up everything for our calc.pi file we made no mention at all about this calc.kv file and this is probably the most important part of our whole app it has everything all of our layout stuff in it so this hasn't actually been bundled into all of this stuff and we could tell that we can go to dist calc and then find the exe file here it is calc.exe if we double click on it it's this i get an error it says failed to execute script calc you couldn't even see it it was on the other screen it just crashed so we need to make some changes to this calc.spec file so let's head over to sublime text and let's go file open and then navigate to our c kb gui directory and then that calc directory and then let's open this calc.spec file and you can see it's just a you know a basic spec file it has some things now one thing to notice look at this path it's got this double slashes for paths that's interesting and that's something you're going to have to sort of keep in mind so okay there's a bunch of changes we need to make to this file the first is we need to add some dependencies up here so let's go from kivy underscore depps we want to import sdl2 and glue right we don't really know what these are we don't really care what these are we just need to put this here if we don't this isn't going to work so that's the first thing we need to do now we need to come down here and designate our calc.kv file right we need to tell our program hey we've got a kv file we need to include it in here so i'm looking here between this pi z and the exe so after this we can just kind of make some space here and i'm gonna go a dot datas right and then plus equals and then square bracket and then parentheses and then code backslash calc dot kv and then a comma and now quotation marks and then we just need to put the path to our calc.kv file so remember these weird double slashes we have to put that there and now this is in c slash kivy gui that's our main directory slash slash calc that's the directory we just created and then calc dot kv that's the name of our file right okay so then we need to put another comma and then data all in caps all right make sure to close our parentheses and close our square bracket so okay that's good there now we need to come down to our call and we need to tell pi installer to kind of look in a directory and grab all the stuff that it sees just to make sure because you know this may work may not work and we also need to reference these things that we just imported so we do all that down here and call equals collect right after the exe i'm gonna put tree and then parentheses and then again c colon slash slash and then kibby gooey slash slash calc slash slash all right and then we need a comma after that and then looking through here we've got our binaries our zip files our data's after data's and before this equals two thing here we need to add one more thing we need to go star square bracket tree and then parentheses p and then for p n more parentheses s d l two dot dep underscore bins plus glue dot dap underscore bins and then a comma after it so basically all of this stuff okay so let's see i think that's good yeah that should be good so okay we've made this change right go ahead and save this file now we need to head back over to the terminal and sort of recompile all this stuff just basically say hey look at that spec file and update accordingly right so to do that we just type pi installer and then calc dot spec and then we need to give this a dash y flag this will delete all the stuff that we've already done so inside of here we've got you know all of this stuff right it can't override those things it needs to delete them and make them again so that dash y gives it permission to do that it says yes go ahead and delete those things and this is calc spec because that's the name of that file we just modified right here calc.spec right so go ahead and hit run on this and this should just take a second it should be quicker than the last one unless there's errors okay so it looks like it was completed successfully and we're good to go so let's head over here and we can test this out we could go to our dist as it stands for distribution directory and then calc and then scroll down here and look for calc.exe double click it and if it worked it should pop up and sure enough it did 8 times 9 equals 72 minus 2 equals point zero go back all right and it seems to work and we've got a little icon that's added because we did the tree thing and uh very cool so that's all there is to it a little complicated a little convoluted but not too bad now you're gonna ask yourself hey there's a lot of stuff here how do i share this with my friends or something right well like i said there's a way that you can make this all into one exe file but it's super complicated and we're not going to talk about it in this video it's kind of finicky and it doesn't always work anyway so this is probably the better way to do it but to share this now we could come over here to our calc directory right inside of here it has all of our stuff and we can just sort of i just press my mouse button and drag this up or you can hit ctrl a on your keyboard to highlight all this stuff and let's just right click and let's go send to compressed zip folder so i'm going to zip this all up into one big folder right and here it is calc.zip you can call it anything you want rename it if you want so now we can go ahead and cut this and say i shared this with a friend right i emailed it to them i dropboxed it to them however you want they downloaded it from my website and then they saved it on their computer i'm going to save this in a folder called uh my calc i guess and so let's right click and paste in that zip file that we just zipped all up now this is one file right so you can send this to people or whatever now to open this they would just double click it and they come up here to extract all and when they do this pops up it says where do we want to extract all those files i'll just keep it in my calc calc so or we could just do it like this i suppose just do it in the my calc directory whatever you want extract these things anywhere you want and when you do this box pops up it's it's unzipping that file and now when we go back to c my calc now all those files are there including this calc.zip now we can delete this if we wanted to or just keep it or whatever so now you can instruct your people to click on the disk folder and then the calc folder and then find calc.exe and double click it and you're good to go if you want to be really sort of sneaky i suppose you could maybe try creating a shortcut before you zipped all these up and then cutting it and then pasting it right here calc.exe shortcut and then zipping all of these files so then when they unzipped it it would be sitting right there and you could just click that and that creates a shortcut maybe you can play around with that whatever but that's all there is to it so not too difficult to make an exe file for windows like i said same thing for mac you just change that dash dash one file flag at the very beginning and you should be good to go so that's all for this video if you like to be sure to smash the like button below subscribe to the channel give me a thumbs up for the youtube algorithm and check out codeme.com where you can use coupon code youtube1 to get 30. memberships and pages 49 taxes all my courses over 47 courses hundreds of videos in the pdfs of all my best-selling coding books join over a hundred thousand students learning to code just like you my name is john elder from coding.com and i'll see in the next video
Info
Channel: Codemy.com
Views: 21,664
Rating: undefined out of 5
Keywords: kivy windows exe, kivy python to exe, kivy app to exe, python kivy exe, kivy executable for windows, python kivy executable, kivy exe executable, kivy standalone, kivy standalone tutorial, kivy pyinstaller, pyinstaller, pyinstaller kivy windows, pyinstaller kivy gui, kivy exe file for windows, kivy exe file for mac, kivy exe file, convert .py to .exe, python executable, .py to .exe, convert python to executable windows, codemy.com, kivycoder.com, john elder, codemy kivy
Id: NEko7jWYKiE
Channel Id: undefined
Length: 13min 0sec (780 seconds)
Published: Wed Dec 09 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.