Pyinstaller Tutorial | Hooks and Hidden import | Converting py to exe | Fixing Fatal Error

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello and welcome guys so in this video i am going to tell you about pi installer what is pi installer why we use pi installer sometimes we face many problems while converting our python file into a executable file so we will also solve those errors in this video so let's get started first of all we will go through brief introduction of pi installer and then we will look hooks and hidden import in pi installer and then we will see how we fix fatal error in pi installer we will also do implementation of how to convert python file into a executable file so let's talk about pi installer pi installer bundles a python application and all its dependencies into a single package the user can run the packaged app without installing a python interpreter or any module basically phi installer convert your python program into a application which you can run without python interpreter or any module installed and command to install pi installer is simply pip install pi installer from command prompt and feature some features of pi installer are that pi installer works with any python version from 3.5 to 3.9 and some libraries supported in pi installer are like some popular libraries like num pipe iqtv5 pi site 2 django wx python matplotlib are fully supported without having to handle plugins or external data manually so these are some libraries which are fully supported by pi installer by default supported by pi installer without having any external plugins so let's talk about hooks and hidden import in pi installer so sometimes pi installer can't reliably find all needed files or may include too many files a hook can tell about additional source file or data files to import or files not to import so basically hooks is a feature of pi installer which tells by installer which additional files we have to consider if we have made any program and we also have some additional files like uh we have created one gui application using python and we have some additional css file so to ah so if we we want to convert that python program into a executable program to tell pi installer about that css file we have to additionally hook that css file so when the module that needs hidden import is useful only to your project store the file somewhere near your source file so we have to create the source file and our python file in the same folder and simply by typing pi installer main dot py double hyphen additional hyphen hooks hyphen dir directory is equal to my script dot py you can write here myscript.css if your additional file is of css file then pi installer will recognize your additional file by simply with this one line of code and your main.py is converted into main.exe then pi installer will also recognize your css file which you have additionally added so in this example i have added my script dot py as additional file so when i convert this main dot py to main.exe then pi installer will also recognize this my script dot py as additional file so let's talk about hidden import sometimes pi installer can't recognize some python library so to make pi installer to identify them use this command sometimes what happened like as we seen previously that by default python can recognize num pipe iqtv5 by site 2 but there is another library pandas data reader library which is not by default recognized by pi installer so to tell pi installer that we have used pandas data reader library in our code we have to use by installer and main dot pys or our python file and dashed as hidden dash import hidden import is equal to pandas data reader so we have to add this to tell pi installer that also import this this library you have one question that sometimes we have to import more than one library so to import more than one library make this hidden import in in a list form now pi installer can recognize pandas data reader as as by default it is not supported by pi installer so by doing this by writing this command pi installer can recognize our pandas data reader library so for unsupported library we can use this so that pi installer can bundle up so now i conclude with this before converting into dot exe make sure you have all additional files attached as additional hook and if there is any hidden import then add it to by typing the following command as mentioned previously so by simply writing your command you will be able to convert your python file into a exe file for more about pi installer check its documentation while going to this link which i have provided here is the pi installer documentation you can read to know more about pi installer so that's all the theory behind pi installer now i will show you how we can use hidden import feature and additional hook feature to use um to convert our python file into a executable file so let's get started so let's start with practical implementation so in this video i am going to convert this python finance dot py file into python finance dot exe so before doing this let's open this file with idle so in this program i have imported pandas matplotlib date time and pandas data reader library so by default pandas matplotlib and datetime is recognized by pi installer but pandas underscore data reader is not recognized by pi installers so if we perform simple conversion by writing our command pi installer and then python finance dot py and then if we press hit enter then we will see that we will get we will get many errors but if we use pi installer hidden import feature then we will successfully convert our python finance dot py file into exe file so before doing this i would like to show you [Music] some by default libraries which are recognized by pi installer and some hidden hooks so to see the all those libraries go to search bar and type pi installer so this is file installer folder open this folder and in this folder you will see this this hook folder loader library fake modules depend boot loader these all are folders so go to hook hook folder and here you will see that tk enter this tutorials django and these are files like matplotlib backend matplotlib tv numpy matplotlib pandas iqtv4 pyqt 5 by side scapi these all libraries are recognized by pi installer by default so these so from here you see which libraries is by default recognized by pi installer and which are not recognized by pi installer basically during the conversion of python file into x exe file pi installer come into this folder and checks whether the import which we have done in program is present here or not and if if he find any file missing then he pops error and so our exe will not run so if there is any additional file additional import which we have done so we have to explicitly add that import in our command so let's go to our file so this is our python finance dot py file which we would like to convert so open power cell by clicking shift and right click simultaneously and open powershell window here so so this is the same location where our python finance dot py file is so to convert our python finance dot py file into exe file so before doing conversion we have to check whether we have any additional file or any additional imports so here there is no additional file for this program but there is one hidden import which is this library pandas data reader library which we have to explicitly add in our command so let's go to powershell and type pi installer python finance dot py and then type hidden double hyphen hidden hyphen import equal to in string form type pandas underscore data reader string close before doing this uh so if i press enter then our python finance dot py file will convert into python finance dot exe file but before doing this i would like to show you by default procedure which everyone can follow by just typing by pi installer python finance dot py file and sometimes we type double dash one file this is all feature we use so if we press enter then see what happen what's happening so pi installer is analyzing this python finance dot py file and it converted one python finance dot spec so here you see that it is looking for hook file so here you see it's popping error import tornado module not found no module tornado found so these are some modules which are not found and here you can see for some error so here you see that pi installer is looking all the hook module which by default present in pi installer and comparing and some this process is taking place so this process is done so here you see that so you see there's error module not found no module win32 this module found these all error are due to our hidden import which we have not done so that's the reason we are facing these type of errors like matplotlib back-end error why we are why we are uh facing this error matplotlib back-end error why because uh pandas data reader is a like python library which because pandas data reader is a python library which extract data from yahoo api and using this data matplotlib plot the graph but here matplotlib doesn't found any any data so it is popping matplotlib back and this type of runtime error that ag backend requires tornado and tornado is not found this type of error are taking that's the reason so to fix it we have to add that hidden import off by installer data reader so before doing this delete all this file which which is created like python finance dot spec file delete this file delete all this file and let's reopen our powershell and type pi installer and python finance dot py double dash hidden import equal to pandas underscore data re da by installer python finance dot py hide and import is equal to and as underscore data editor and hit enter so again our process is started so here see that our process is completed and there is one error win 32 error but this error is fixed and we will not get any issue in that so see our process is complete so let's get to check our finance python finance dot exe file so here two folder is created based on build and this is python finance dot spec which is created so our exe file is inside this folder list folder this is the main our main file which contain all the additional files and everything about that exe file so these all are the files which are responsible to run this python finance.exe file so let's run python finance.exe file so here you see that it is asking to enter ticker symbol so i am entering tesla take our symbol dsla and it recognizes and output is displayed with this graph so this is our output so this is uh using pi installer we are able to create a software this is the software which you can use which you can transfer to your friends they can simply run this without using any python interpreter without using any python library they can simply run this but make sure that these all files are included so this is the small software which you have created using pi installer so you can transfer this folder to your friends and your friends can run this python finance dot exe file by simply double clicking this without using any python without using any additional libraries they can access it and they can use this see it's working so guys if this is helpful for you then hit like and subscribe my channel for more update and also share to your friends thanks a lot thank you for watching this [Music] video [Music] you
Info
Channel: SPOTLESS TECH
Views: 6,050
Rating: 4.5324674 out of 5
Keywords: Python, Pyinstaller, pip, powershell
Id: WPsaFQSO7Pk
Channel Id: undefined
Length: 19min 26sec (1166 seconds)
Published: Tue Jan 05 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.