How to Convert any Python File to .EXE

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
in this video I'm gonna be showing you how to convert any Python file or Python project into an executable file that you can run on a machine that does not have Python or the said packages installed so this is gonna work for Python scripts that involve other scripts so you're importing other modules and stuff like that and it's gonna work for just individual scripts as well what we're gonna be using is called PI installer so the first step we need to type CMD in our window is bar down here and just run it as an administrator just for some purposes for installing stuff so this is gonna require that you have pip installed if you don't have pip installed well it defaults comes with Python I'm gonna be showing you how to do that in one second so first thing we want to do is just type it in our CMD now if you've got something that looks like what I got and you did not get any errors go ahead and skip to the timestamp that I'm about to put in the middle of my screen now if you did not watch until that timestamp because I'm gonna be showing you how to install pip really quickly so the first issue you could run into and why you'd be getting this says something like pip is not in path it's an unrecognized command so the easiest way to fix this is to go to just search environment variables in your bottom bar here click edit the system environment variables go to environment variables in path click edit and then here click add or add click new ok so once you click a new in here you're going to type in the body called the directory of your Python file so you can see for me I'm using anaconda and this is the directory I also have a regular Python one that's not currently in my path so what you need to do here is simply find where your python is installed and add that to the path if you don't know where it is i'm gonna put up a default python install location on the screen right now that you can simply put in to the path once you've done that click OK click OK and you should be done click Oh click apply and then click OK again and it should be added to path once again try to click try to type in pip if this does not work then you don't have pip installed in your system and what I would recommend to you is just search python click on python org go to downloads and reinstall python when you do this it so uninstalled python first do this once this downloads and installs just wait one second for it to come up when I click on this it's going to say what do you want to run this file run the file modify and then you can add pip by just clicking on this little check mark here and you can also add it to the path automatically so here say add Python to environment variables click the check mark and click install so as you don't actually have to uninstall Python first sure you want to cancel yes we're gonna cancel cuz we already have that done okay so once you've done that now we're ready to move on to creating our executable file ok so what we're gonna do first of all is we have to go to the directory where we want to create that file so I'm gonna go in my python file and i'm just gonna go to games i'm gonna go to golf game and you can see that here i already have an executable file created this is just because i test it out before to make sure everything was working so what we're gonna do in here is we're gonna simply type CMD once CMD comes up what you're going to type is pip install pi installer like this ok you should run through this you can see that it's not installing for a because it's already installed and everything should work fine there once you have pi installer installed then you can move to creating your executable so to do this you're simply going to type PI installer and then you are going to type the name of the file that you want to create an executable of in this case I want to do Main now it's a few flags you can put here the first flag is - - one file I recommend that you type this as what this is gonna do is create everything in one executable file rather than having a bunch of other files so I recommend you type that I also recommend you put hyphen W here if you don't want your Python file to bring up the console when it runs so if you're running a graphical game with Pi game or something you're gonna want - W if your project works within the console then don't put - W otherwise it's not gonna work okay now you type your script name I'm gonna say Maine Pyaar py and click enter now this takes quite a while especially if you have a project with a lot of dependencies and a lot a project like modules and stuff to import so just wait for that to run I'm gonna fast-forward through this okay so now that's completed we can actually exit out the command prompt window and I'm just gonna show you how to actually run your file so you can see here that in the directory it should have created two folders D is T and build now build you can actually delete you don't need this folder this may not spec you don't need that either so all you need is this D is T so once it loads up you can see that we now have a executable file which is main now if you only had one Python file and it has no dependencies no images no other imports or anything that you created so like for example in my golf game I have Start screen courses and physics which are imported by main then all you have to do is simply click on this executable file and it will run everything and everything should work now in the case that you do have dependencies which you probably do what you're going to want to do is drag this executable file into the main directory where those dependencies are so for example here so we can delete this di s T folder now I need to import images from the image folder and you can see I have images here I have all these other Python files so I'm gonna need to make sure my executable file is in this main directory now if that's all you wanted to do everything should be working fine just double click on this and do note that since it is such a large application file with a lot of dependencies this is gonna take a while to boot up typically for me it takes between one and two minutes actually start running as pygame if you're running just a single script it should not take that long ok so now that we're done that you guys are welcome to click off the video however I am gonna show you one really cool thing to make all of this into one file so that you don't have a big folder like this whenever you trying to run something so all this stuff can be condensed into one folder using something called NS is ok so we're gonna do is we first need to download install NS is to do that you can simply just click the link in the description all you can also do is just type NS is you can click on the website and wait for it to load up ok so now that we're on the website you can simply click on download it should bring you to a page and you can download NS is just run through and click all the default commands it's not very important the installation process of that ok just do whatever was recommended for you alright so now that you have this it should pop up as a desktop icon otherwise you can simply type NS is double click it run it you see it says compiler here simply select compile n SS or installer based on zip file so actually that leads to B the next point what we need to do first of all do is click on the folder in which we're trying to like create a big I don't know whatever you want to call XQ before and we're simply gonna click on it and click send to and then compressed compressed zip now you can see that I already actually have a compressive folder of golf game so we don't need to do that okay so now you've done that click installer based on zip file and simply find the zip file so for me it's right here in Python games you double click on your zip folder and then you can just leave all these the same so now installer name obviously you can change that's what you want interface modern is fine and everything else is just standard ok once it extracts all these files simply click on generate now this will take a while because it's going through a ton of files at least in my case it's like something like 250 megabytes so expect to be waiting here for about a minute or two I'm just gonna fast forward and then talk about the next steps ok so now that's complete you can either click test to try to test out your file or you can click close ok so now that you've done that you should have something that looks like this kind of a weird looking icon you can double click on it when you do this ok so now it brings up a folder like this or installer you can simply select where you want to install click install and then what it's going to do is simply install this folder in that directory that you chose so now if you wanted to export this file or you want to upload it or give it to a friend or something you can simply give them this one application and they can have everything from that and they don't have to have Python installed on their system or any of the packages or anything that you had when you created the game as its going to automatically create them in this executable file when you make that executable okay so that's been it for this video if this helped you out please make sure you guys leave a like on the video and subscribe to the channel for more Python tricks and tips and with that being said I guess I'll see you guys in another video [Music]
Info
Channel: Tech With Tim
Views: 1,673,668
Rating: undefined out of 5
Keywords: tech with tim, convert py to exe, convert .py to .exe, how to convert python to exe, convert python to executable windows, convert python to executable, how to make a python executable on windows, .py to .exe, how to convert python to exe using pyinstaller, python to exe
Id: UZX5kH72Yx4
Channel Id: undefined
Length: 8min 24sec (504 seconds)
Published: Wed Nov 28 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.