Build an executable file (.exe) from a python file (.py) using one simple command.
- Tejas Achar
- May 2, 2020
- 1 min read

Photo by bongkarn thanyakij from Pexels
I came across this thought of building an executable file while tinkering with PyQt5 GUI framework by QT.
If you are building a GUI application for windows, you will need to build an executable file, be it any language you are coding in.
While coding on python you might have used a lot of libraries and while building a .exe file, all these libraries must be packaged together, so that you can use the application anywhere without having any dependency issues.
PyInstaller is a python package, which is used most commonly to build executable files.
All you have to do is go to the directory where the .py file is located on the file system and open command prompt
Lets say you have a file named "My_Python_file.py"

and use the following command:
pyinstaller My_Python_file.py
And all these folders will be generated:

You can find the executable file in "dist" folder

And there you go, you just built an executable file.
Adding to this there are a few configurations which u can play with in pyinstaller.
1. Lets say you just want the executable file in the dist folder and nothing else.
you can use -F for this operation
pyinstaller -F My_Python_File.py
2. By default when you launch the executable file, it also launches a python console in the background. If in case you don't want that to happen use -w in the command.
pyinstaller -w My_Python_File.py
You can also merge these two parameters in the same command.
You an also find the project i built using PyQt5 here :
Will write more about this application in the upcoming posts.
Peace.
Comments