Image illustration python

Tl;Dr

Use PyInstaller to build your single file executable for your app.

How to

You got your app with all it python files. Now it is time to deliver it to your users. Lets make it clean and easy to use : lets build a single file that the user simply need to double click on.

First of all we will install PyInstaller :

pip install pyinstaller

Then when navigating in your app app simply run PyInstaller like :

pyinstaller yourprogram.py

This should build you your executable, given it is a simple enough one. If everything goes according to plane you will have a nice “dist” folder containing your bundled app.

Things goes wrong

Maybe you have a more complicated app and it is not that simple. PyInstaller will build you a “yourprogram.spec” file. This file contains all the dependencies of your app. Most certainly your app is using some hidden dependencies that PyInstaller cannot guess. For example I was using gevent as a socketIo server, but it was dynamically loaded by the flask-socketio package. I had to add “engineio.async_gevent” to the list of “hiddenimports” in my “yourprogram.spec” file to make my app work fine.

Once you added your hidden dependencies, you need to run PyInstaller on that spec file (not on the py file or it will overwrite the spec file you just changed) :

pyinstaller yourprogram.spec

This hidden research of dependencies might be a bit tedious but the result is worth it when it comes to make your app easy for your user to use it ;) .