Executable for our demo application

kodark

kodark

Posted on February 20, 2021

Executable for our demo application

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
Enter fullscreen mode Exit fullscreen mode

Pyinstaller also supports encryption of Python bytecode modules, in order to use this feature, it must be installed:

pip install pyinstaller[encryption]
Enter fullscreen mode Exit fullscreen mode

As we have installed the required libraries, we are going to explore how can we distribute our application.

Create exe file (windows)

Remember to 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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Hiding console window

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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.

💖 💪 🙅 🚩
kodark
kodark

Posted on February 20, 2021

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

Executable for our demo application
python Executable for our demo application

February 20, 2021