In our previous posts we have explored Eel library, along with its options and we have created a demo application.
This post is mainly dedicated to pyinstaller, which is a python library which allows to easily distribute python code. Pyinstaller will help us to distribute our eel application.
First step is to install pyinstaller:
pip install pyinstaller
Pyinstaller also supports encryption of Python bytecode modules, in order to use this feature, it must be installed:
pip install pyinstaller[encryption]
As we have installed the required libraries, we are going to explore how can we distribute our application.
cd to our project folder, our python script is named app.py and "web" folder contains out html, css and js. We can create an exe file (under windows, .so under mac or linux) with the following command:
python -m eel app.py web
Pyinstaller will analyze our python script, will create a spec file, will create a folder named build for holding log and working files and finally will create a folder named dist for writing the executable. Dist folder is the one we should send to our users.
The output from the previous command will be a folder (dist) which contains all python dependencies and our exe file, which is the one we should run. However, it would be better to distribute a single file instead of a folder with several number of folders, subfolders and files.
A single executable file can be built with the following command:
python -m eel app.py web --onefile
With the previous command, a single file has been created, this is easier to distribute and for the user; however, if we run our exe file we can notice that the chrome window appears but a command window also does.
Hiding the command window can be achieved by adding a flag to our current command:
python -m eel app.py web --onefile --noconsole
Now we have a single executable file and once it is executed, a single window will show up. Finally, what we can do is add encryption of our bundled files, this can be achieved with the key flag and a key of lenght equal to 16.
python -m eel app.py web --onefile --noconsole --key=abcdefghijklmnop
Now we are capable of distributing our python applications with a user friendly GUI in a single executable file.
There is still one issue, executable files will work only on the same platform where it was built, e.g., an executable file generated on windows 10 - 64 bit won't work on windows 10 -32 bit, or in windows Server. Obviously, it also won't work on MAC OS or linux based OS.
So you must build your executable on all the platforms where you want to distribute your application. For achieving this, you can explore task automation tools which allows you to perform continuous integration and continuous delivery.
One CI/CD popular tool, is Jenkins. We might have a Jenkins series in the near future.