Convert Python Files To EXE using PyInstaller | PyGame Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
in this video i'm going to show you how to package up your pygame files into an executable that you can then distribute the tool that we're going to use for this is pi installer so the first thing to do is bring up your command prompt and the way i like to do it is click in here type cmd and hit enter and it will bring up the command prompt but importantly it opens it already in the folder that you are currently in so it just makes things a little bit easier now the first thing to do is type out pip install pi installer now for me it says requirement already satisfied because i already have it installed but for you it might just take a couple of minutes to install this package you may at this point run into an error that says pip is not recognized as an internal or external command this is a common error and i'm just going to put a link in the description that explains how to solve it it's it's quite straightforward to fix so once you've got pi installer ready the next thing to do is make sure that you are within the folder that your script is located so in my case the platformer.pi is the file that i want to package up and i am in the correct folder so c forward slash platformer so then you just type pi installer and then the name of the python file which in my case is platformer dot pi now after this there are a couple of well there are many different options and settings which can be added in as flags so for now the only one i want to add is dash dash one file now hit enter and it's going to start creating the executable for you now this one file flag it essentially does exactly what it suggests it creates the executable as one individual file so it makes it easier for you to then distribute so we just give that a minute to run through now you'll notice that it's already created a couple of different things there's a new folder called build a folder called dist and then a file down here platformer.spec now you actually don't need a lot of this the only thing that you're going to need is the file that gets created in the dist folder so i can see now this is finished so if i go into the dist folder there's my platformer.exe so let's run it and see what happens so you see it comes up but then it closes down straight away so obviously there's some kind of problem there but it doesn't give me any kind of error messages so it's very difficult to debug so this is where another useful flag comes into pi installer so if i type it out again pi installer let's just go back up to the correct folder so it's pi installer the name of the file which is platformer dot pi then the first flag which is one file and then the second flag is going to be dash dash windowed so if we run this again now because all of the files already exist it actually doesn't take very long so that's it finished now if i go into the dist folder again i can run this file and this time it will come up as a window and actually stays so now you can see what the error is so here it's saying that it's failed to execute the script because this file that it's trying to load which is in the folder img it's not here it can't find it within this location well that makes sense that's correct so if i bring up the code of this game one of the first things it does is it tries to load up this image here and it's looking for it in the folder img that folder is not here it's not within this dist folder it's actually within the root folder so there's the img folder and that contains the song and all the other assets for this game so what i actually need to do here is take this executable copy it and move it into the root folder so basically it needs to be sitting next to the python file if i run this up again it should start successfully and that's it now the game is fully loaded and working [Music] and that's essentially it so now if you want to distribute this you don't need all of these files you just need the executable and all the assets that the game uses so you take this all of the level data and the assets that are within the image folder and just say add it to an archive and there you go that's all that you would need to then send out so the stuff that's within build and dist none of that is needed for this so if you found this useful then please leave a like and consider subscribing thanks for watching
Info
Channel: Coding With Russ
Views: 63,895
Rating: undefined out of 5
Keywords: Python, Python tutorial, python platformer tutorial, python beginner tutorial, pygame tutorial, pygame platformer, pygame platformer tutorial, pygame beginner tutorial, pygame tutorial for beginners, python game, python game tutorial, pygame, programming, game, coding, python for beginners, python programming, platformer, pygame shooter, pygame collision, pyinstaller, python to exe, python to exe converter, pygame to executable, pygame exe, python pyinstaller, pyinstaller tutorial
Id: 2X9rxzZbYqg
Channel Id: undefined
Length: 4min 24sec (264 seconds)
Published: Sun Apr 03 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.