Creating a Stand Alone Executable from a Python Script using PyInstaller

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys in this video I'm going to show you how you can create a standalone executable file using your Python scripts so let's say I have a project and it contains some Python scripts or a Python script and let's say I want to convert this test dot py into an executable file so on Windows it will be dot exe file or on Linux it will be a binary file which I can execute by double clicking so for that for converting your Python scripts into an executable file we can use a utility called PI installer so you can see there is a website called PI installer dot o-r-g and you can find more about this PI installer utility on this website and PI installer is a Python application which creates standalone executable file under Windows Linux or your Mac's operating system so for using PI installer you need to have pip installed on your operating system so what is PIP first of all if you don't know what is PIP you can just go to this website pi PI dot o-r-g py p i-- dot o-r-g and pip is a package management system which is used for the management of the Python applications so for using PI installer you need pip and how you can install pip on your operating system you just need to install Python on your operating system pip will be automatically installed with the installation of Python so you don't need any extra strap to install this pip on your operating system so if the Python installed the latest version then pip is going to work I have already created a video about how to install Python on your Windows operating system let's say so I will just put the link in the description so you can see that video and move ahead so once you have installed Python you can just open the command prompt and once the command prompt is open you can check if pip is installed or not using this command just give P IP - - version and if this command gives any useful reply for example in my case it says pip and the version of pip which is installed on my system and which python version it's using so this is the python version it's using and this is the pip version which is installed on my system so once this command works then what I can do is I can go to the PI installer website and you can see it's a simple command to install the PI installer so you just need to give this command pip install PI installer in order to install PI installer so let's copy and paste this command pip install PI installer and then press ENTER and it will take a few seconds to install by installing utility using pip so once this installation command is finished successfully you can see it's finished successfully on my terminal what I will do is I will just go to my installer website and see how to use it so it's the it's a very simple usage of this pious taller command you just need to give the PI installer command and after that the name of your python script so let's do that so what I'm going to do is I'm going to go to this folder where my python script is there so I'm going to just restart my command prompt and once the command prompt is open I'm going to just copy the part of this python script and then I'm going to just say CD and the path and then press Enter let me just make it a little bit bigger and let me just move this folder Explorer so in order to convert this test dot py a script into the executable file you just need to give this command PI installer space the name of your python script which is test dot py in my case and then press enter and it's going to take some time and you can see some folders and files are created by pi installer inside the project folder for you so once this pi installer command is finished you will see in addition to your python script there are a few folders which are created so the interesting folder for you will be this folder which is the DI st or dist folder so i'm going to go inside this dist folder and then i'm going to go inside the test folder so this name will be the same as your python script name so i'm going to go inside this folder and here you will be able to find an exe file with the same name as your python script so because my python script name was test dot py that's why the executable file name is test dot exe file so let me just double click this file and you can see when i double-click this executable file it will give me the same output as my python script is going to give me so this is how you can convert your python script into our executable file so let me also show you the output of the python script so let me just clear this console here and then I'm going to just say Python and then test dot py and you can see the executable file gives me the same output as this command is giving me now you might observe one minor issue here and this issue is you can see there are lot of dependency files which are created by PI installer for just running this test dot exe file so what if I just need to create this test dot exe doubt all these dependencies so let's go back to my project so this was the project and I'm going to delete all these generated the files and folders which were created by PI installer and once again I'm going to give the same command which is PI Staller test dot py but I'm going to add one extra flag here which is - - one file flag so what this flag will do is it's going to just create one exe file without the dependency files so let me just give this command and let's see what happens when I give this PI installer command with one file flag so now you can see all these folders are recreated but when I go to the dist folder here you can see this time only test dot exe file is created without any extra dependency right so all the dependencies will be bundled with this exe file and only one file will be created and this is much better than creating all the dependencies and just transferring all the dependencies to your client or anyone so let me just double click this also and you will see it's going to give you the same result so if you want to create only one exe file without any dependencies you just need to give this flag which is - - one file and you will just get only the exe file once again let me just give the CLS command to clear the terminal now I have one more example for you so let me show you the second example and let me go inside this folder which is tkinter project and let me just run this project so I'm going to just go back one folder and then I'm going to CD into the Kinta underscore project and let me just run this python script quick and this is the output of this Python script so this is a window which I want to open and I want to convert this Python script into an executable file so this Python script uses Kinta for creating this window so there are some dependencies which you need to import inside your Python script now in order to convert this into an executable file you might already know the answer how to convert it you just need to give this command PI installer space - - one file and the name of your script which is going to create an executable file using this Python script and once again when I go inside this dist folder you can see this main underscore window dot exe file is created and when I double click on this window then there is a terminal which is opened first and then after few second your real application will start so now the real application which is this kinter window is started now so you can see us little problem here which is this terminal window always opens before opening your real application which is this Bindu so how can I just remove this terminal and I just want to open this registration form without this terminal so there is one more flag which you need to add in order to achieve this so I'm going to just close these two windows and terminal and for now let me just remove all these directories so delete and let me just clear the terminal and in addition to your - - one file flag what you need to do is you just need to give one more flag which is - W ok so PI installer - - one file space - W and then your script name and then I'm going to just Center which is once again going to create these directories so once this command is finished I'm going to go once again to the dist folder and run my main underscore Windows dot exe file and this time no terminal will open only your application window will open without opening any console terminal so you can see only my real application is opening without opening any extra console terminal so - W is for opening your real application without any console output now there is one more thing which I want to show you here is for example your project contains some extra dependencies on some extra things which are related to for example your Chrome extensions or any other thing what you can do is you can use a utility called nsis which is open source utility so you can just go to this website which is NSIS dot SourceForge in the description and when you reach to this page you can see the download a button on the right hand side so I'm going to click this download button which is going to open this page and then I'm going to just click on the download link here and after a few seconds this executable file for NSIS utility will be downloaded on my system you can see it's about 1.4 megabytes so it's not a big file so you can directly install it and then run this executable file and once you run it let me just minimize the browser and also let me just minimize these windows and this is the Installer window so I'm going to just click Next I agree and then leave everything as default next and this will be the location click install and once this nsis utility is installed you can just leave this checkbox checked which says run and is which is going to run your NSIS application so this is the an sis menu what you need to do is you just need to click on this link which is installer based on zip file so just click on this link installer based on zip file and provide the path for your directory so what you can do here is once you have created your Exe file so there is this Exe file you can name this folder anything for example I will just leave it as dist folder and then you just need to convert it into a zip file so let me convert it to a zip file so I'm going to just say add to archive and then I'm going to create a zip file and then I'm going to just say ok which is going to create this zip file and inside this zip file you already know my Exe file is there so once you have created your zip file just copy the path of this directory and go to this window which is opened using NSIS and then just give the part of your zip file so this is the zip file I'm going to just give the part of this zip file and then I'm going to just click on this generate button which is going to generate you can see this dist dot exe file ok so once this this dot exe file is created using your zip file you can test this using this test button so just click on test and it's going to open this kind of installation windows so this this dot exe file you can just give to your clients or your colleagues in order to install this Exe file on their operating system obviously it should be a Windows operating system so I'm going to just double click on this Exe file and it will work like a normal installer now one thing to note about PI installer utility is if you want to create it a Windows Exe file you need to run PI installer on your Windows operating system so if you want to create a Linux binary using your Windows operating system PI installer it will not work okay so if you want to create a executable file you use Windows operating system with PI installer if you want to create a Linux binary then just run that python script with PI installer using that operating system so that's it for this video this is how you can create a standalone executable file using your Python script I hope you've enjoyed this video and I will see you in the next video you
Info
Channel: ProgrammingKnowledge
Views: 162,476
Rating: 4.8746023 out of 5
Keywords: PyInstaller, .py to .exe, Python Executable, .exe, PyInstaller Quickstart, py2exe, NSIS, Nullsoft Scriptable Install System, Programming Language (Software Genre), Python (Programming Language), Python, Python Tutorial, Python Tutorial for Beginners, Python for Beginners, Python for Beginners course, program in Python, Python course, python tutorial, python scripting tutorial, Online Course, Python Guru, Learn Python, python 3
Id: t51bT7WbeCM
Channel Id: undefined
Length: 16min 29sec (989 seconds)
Published: Sun Jun 02 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.