Convert GUI App to Real Program - Python to exe to setup wizard

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
one of the coolest use cases of python is making simple goalie applications but there's a big difference between creating an app for your personal use and between Distributing it all across the web reaching many many people who don't necessarily know anything about python so in this tutorial I will show you just how easy it is to convert your python apps into full-blown professional software and the result is a single setup file which anyone can download and install on their system so are you ready Let's Roll the app will convert today is my random recipe picker which we have created together in a previous tutorial using sqlite and kinter but don't you worry this will work just fine for kiwi Ki vmd pi qt5 and other guise now in this example we are dealing with a python file a database as well as a bunch of assets specifically images and true type fonts so if your project contains similar files this tutorial will save you lots of headache now the Last Detail I should probably mention is that I've slightly modified the database of the original recipe picker according to your suggestions so instead of having many many many many many many tables we now only have two of them one that stores the recipes and the other the ingredients so first things first we will navigate to my random recipe picker repository and we can either clone it like true profession journals or we can just click on code and then download zip which is the lazy approach then we will extract it somewhere in our file system we'll of course navigate inside where we will only keep the folder named relational database complete project windows we can dispose of everything else now inside this folder you will find all our project files but in order to use them we will need to install some requirements first now by requirements I mean dependencies or the python libraries our kinter app utilizes now luckily I've prepared this really nice file for you so we can install all those requirements at once for this we will need a console or a terminal and in my case I am using Anaconda now if you're not sure how please check out this tutorial of mine now let me quickly enlarge this text so we don't need a microscope to see it now the first thing we'll do is create a brand new working environment with conda create dash dash name and we will call it inverter or any other name you'd like we will also install python 3.9 inside it and let's hit enter now if you're looking for the equivalent vnf command you can of course find it in the description we'll then proceed with why and we can Now activate our new working environment with conda activate converter now once we are inside this environment we will copy the path of our project folder we will then navigate there with our terminal by using the CD command as in change directory and then we will paste the path which is copied now once we are in the exact same directory as our requirements file we will then type pip install Dash R requirements.txt and beautiful we've installed all those libraries at once next we will need to find a way of bundling our script data and assets into an executable file now in the previous tutorial from many many years ago we've used a library called autopi to exe and it had a beautiful graphic interface today we will use a library named Pi installer instead which is the command line equivalent or how I like to call it autopy's mom so let's quickly install it once again with Pip and we'll do this with Pip install Pi install color since we've used pip earlier we might as well be consistent now we will make sure that our terminal is in the exact same folder as our script file which in our case is recipe picker.py and it's basically where our kinter app lives now if we are indeed in the exact same directory we will then type Pi installer recipe picker Dot py and we will let Pi installer run its magic it might take you a minute or two now once we see this last completed successfully message we will go back to our project folder to discover a whole bunch of new files so first we have two new folders one of them named build and the other is named dist or distribution and this is ultimately where our executable file will be located once we will create it okay now in addition we have this recipe picker.spec file which we will briefly discuss in just a few moments now an important thing to mention is just because we are able to run our app perfectly through the terminal it doesn't mean that it's adapted to Pi installer so for example we can now run our program with python recipe picker dot py we will verify that it's fully operational yep it works great but the only problem is we'll still need a terminal in order to execute it it is not designed to run on its own just yet so let's take care of that for this we will need a helper function which I did not write so I'll refer you to this thread on stack Overflow and you can of course find it in the description we will then scroll down and we will copy this entire resource path function which now till use was kind enough to provide so let's quickly copy it and let's paste it inside our script right below the Imports now if you'd like to be extra nice you can always copy the URL of this thread and you can include it inside your code as a comment now for many many systems this function works perfectly well you can find evidence of it all over the web however both in the case of my rogue build as well as my Alienware I had to adjust this underscore may pass to underscore may pass 2. now this is very important I got stuck here for a very long time so if one of them doesn't work please try the other now without getting into too many details the reason why we need this function is because Pi installer expects to find your assets as in images data and fonts inside a temporary folder named sis dot underscore may pass or in my case may pass 2 which is very very different from our project folder as it is not temporary at all okay so basically resource path helps Pi installer with finding the correct location of your assets now the way to use it we will simply copy this function call and everywhere we load an external file we will wrap its path within resource path there you go and it will repeat it for all our assets okay so we took care of the fonts we'll do the same for our data and lastly both our logos beautiful now before I forget let's scroll up and since resource path is using members of the CIS and Os modules we will of course need to import them so import sys and import OS now we don't need to install those modules because they come built in with python so it's quickly save this file and let's have a chat about this recipe picker dot spec file which I've mentioned earlier now you will find many many threads on stack Overflow instructing you to specify all your assets inside this file for example if we go back to our thread and we look for the correct answer you can see that they append the path to their assets inside this data's property right so there's this very long path and they want you to do it for all your assets however I discovered that it makes no difference at all you can leave your spec file as is and everything will work just fine so I feel very bad for all the folks who typed those very long paths in here especially if you have many many assets so please feel free to ignore the spec file unless you have specific errors that guide you there for example an error associated with the hidden Imports okay you may encounter it and only then this becomes relevant now the last asset we are yet to take care of is the icon of our program now I find that the easiest solution is to navigate to a site such as image.onlineconvert and then to drag and drop one of our logos into it okay so let's go for this bottom logo because it already kind of looks like an icon right so let's drop it in this green box and let's hit start we will then download it we will cut it from the downloads folder and we will paste it inside the root of our project and instead of having this very long name we will rename it oh sorry we will rename it to Icon boom done and we are finally ready to convert our scripts data and assets into an executable file so back in Anaconda we will type Pi installer dash dash name and in my case I'll call it recipe picker in camel case now since we'd like to generate a single executable file rather than a giant messy directory we will add the dash dash 1 file flag now in addition since we'd only like to display the graphic user interface window rather than a console beside it we will add the dash dash windowed flag next we will set the dash dash icon to Icon dot Ico which we've just generated and saved in the root directory and then lastly we'll specify the name of the script which in our case is recipe picker.py and are you ready let's convert it now this may take you a minute or two and beautiful once everything was completed successfully we will navigate back to our project folder and then to the distribution folder where we can find our brand new executable file so let's quickly checked that everything works as expected and oh no it looks like Pi installer is having some issues with finding our assets so let's see exactly what's going on and yeah it kind of makes sense our path is completely messed up we start with a bunch of double backslashes and we end with a single slash well this can't be right so it's quickly fix it back in our recipe picker dot py now everywhere we see a slash inside our paths we will replace it with a double backslash we will of course do this for all our assets and boom now let's quickly save it now in addition I don't know if you guys have noticed but there's another problem here so it seems that Pi installer is not looking for our assets inside the root directory our project folder it is actually looking for those assets inside the distribution directory well that's an easy fix so let's just close this error let's navigate to the project folder let's cut the assets data and fonts folders We will of course paste them inside the distribution folder easy peasy now since we made a bunch of changes we will need to convert our app once again so back in Anaconda we will hit the up Arrow which will fetch the recent command and then we will press enter once again now once Pi installer is done we will make another attempt at running our programming fingers crossed and oh my God look at this beautiful app so let's quickly make sure that it's fully operational and yep sure is congratulations folks we were successfully able to convert our python files into a full-blown executable program but there's just one problem if we want to distribute this program we will need to include the executable as well as those three asset directories which is not exactly what we were aiming for traditionally when we download a software we download a single setup file instead so let's quickly take care of that for this we will use a software named Eno setup which is free of charge both for personal and both for commercial use so if you'd like to read more about it please check out this section at the very very bottom now let's quickly go ahead and download Eno setup and we will go for the stable release we will then select one of those download links I'm gonna go for the US one even though I don't really think it matters now let's quickly install it and we will of course follow the installation instructions of the setup wizard which is ultimately what we're trying to implement for our recipe picker now once the installation is complete we will then launch Eno setup and we will create a new script file using the script wizard it will of course hit next and we will fill in some basic information about our program now in my case the name is random recipe picker the version can remain at 1.5 because the previous version did not have a relational database and this one does so kind of makes sense to me now the publisher is probably python simplified and the website is python simplified .org even though I've paid for another year of the ca domain so python simplified CA also works now here we specify the default destination folder of our program and since program files is very traditional we will leave it as is now in addition we would like to allow users to change it if they'd like so let's go next now here we specify the path to our executable file which we have just created with pi installer so let's go ahead and browse it will copy the path of our distribution directory and we will fetch our recipe picker.exe now in addition we will need to specify the folders that our executable depends on so we will click on this add folder button we will navigate to our distribution directory and we will load all our assets folder by folder unfortunately there's no faster way of doing this now in this pop-up screen please make sure to select yes because we want to include the assets within the directories and not just the directories themselves okay so yes for sure and we'll do the same for the rest of our asset folders perfect and we can double check that all our assets were included if we see this asterisk at the very very end of the paths beautiful let's move on now my rule of thumb with things I'm not familiar with is if I don't know what it is I don't touch it so we will uncheck this check mark because I have no idea what a DOT myp file is all about if you do please do as you wish I'm just gonna skip it now in addition we would like to create a shortcut both in the start menu as well as on the desktop just to make our app extra accessible now if you have any license associated with your your program this is the perfect place to load it it's actually the only place to load it now in my case I'm gonna go for the MIT license which I found on this open source initiative website we will scroll down we will copy this entire license text and we'll paste it inside Sublime which is the text editor I'm using for this tutorial we will do this in a new file and we'll change the year to 2023. now the copyright holder I'm not sure if it's python simplified or me so I'll just type Maria Shah and in my case it's not that important because I allow anyone to copy modify merge publish distribute sub license and even sell my program so I have no restrictions whatsoever but in your case if you have any type of restrictions on your license please do some proper research this is a legal document and you don't want to mess it up so let's quickly save it we will call it license Dot txt and we'll save it in the root directory of our project we'll then navigate back to Eno setup we will browse and we'll fetch this new license document and we will move on now here we get to choose if we'd like to install our program for all windows users or just for the current user now in my case I'm gonna skip it because I really don't care now in the next section we select the language of our app in my case it's English now in this menu we specify settings associated with the setup file which Eno setup will generate for us so first we will select an output directory in my case I'll just go for the Parent Directory of our root which is random recipe picker Dash main but it doesn't really matter you can do this for the desktop just make sure you remember where you saved it so you can fetch it later on it will then specify the name which in my case is random recipe picker in Upper camel case then underscore windows then underscore 1.5 which is the version and then I guess setup right and if you need some inspiration I highly recommend to check out your downloads folder where you can probably find some recent setup files which you've downloaded regardless of this tutorial um and as you can see there is really no one-size-fits-all convention steam doesn't even bother to specify the operating system or the version or anything else besides it's a steam setup so it's entirely up to you okay now we can also choose the icon for our setup file and you can of course go for the exact same icon as your executable in my case I'll go for something a bit more traditional I've prepared it in advance there you go I'm sure many of you are familiar with this icon you can find it in a simple Google search okay so I'm gonna go for this one now in addition we can even set a password for our setup file some sort of a product key but you already know I'm not gonna do this so let's just skip it now lastly we will leave this hashtag Define check mark on and now we can finish our wizard settings now this will convert everything we've done in the Wizard into a compilable file but we cannot compile it just yet we will need to make a tiny adjustment to the asset directories so it will select no and we will scroll down all the way to the files section and what we need to change here is the destination directory so instead of searching for our logos inside the distribution folder which is indicated by curly brackets app we will search for them in the distribution folder slash assets and we will do the same for the rest of our directories we will do this for the database so curly brackets app slash data and we'll do this for the fonts curly brackets app slash fonts now this is a very important step if you don't do this Eno setup will place all your assets inside the exact same directory as your executable and as a result your program will fail so if you have any subfolders inside your distribution directory you have to manually specify them here it's not going to happen automatically folks okay so let's quickly save this file somewhere on our desktop maybe just in case who knows let's call it uh just in case I will delete it shortly and let's go ahead and compile either by pressing Ctrl F9 or just this lovely little button and awesome once we see this finished message we will then navigate to The Parent Directory of our root which is random recipe picker Dash Main and there you go here's our lovely setup file now we can of course test if this file works as expected in the current system however a better test is installing it in a completely different system just to make sure we didn't miss anything so let me quickly jump on my Alienware and we'll go from there okay so let's quickly double click our setup file and wow we are immediately presented with our license agreement so let's quickly accept it and let's see if everything worked let's click finish holy smokes you guys here's our beautiful application good job now let's quickly check that it's fully operational yep it works as expected now let's have a quick look inside the program files so program files 86 and then random recipe picker beautiful everything is so organized I think it looks so much better than just dumping all our files in the exact same directory as our executable good job now we know exactly how to turn our executable and assets into a single setup file amazing and thank you so much for watching if you found this tutorial helpful please share it with the world and don't forget to give it a huge thumbs up if you'd like to see more videos of this kind you can always subscribe to my channel and turn on the notification Bell now if you have anything to say or any questions please leave them in the comments below you know I read your comments all the time and I'll see you very soon in another awesome tutorial in the meanwhile bye-bye
Info
Channel: Python Simplified
Views: 296,085
Rating: undefined out of 5
Keywords:
Id: p3tSLatmGvU
Channel Id: undefined
Length: 23min 27sec (1407 seconds)
Published: Fri Jan 27 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.