Home

June 20, 2018, 2 min read

Bundled Single Executable on Windows

Windows Single Executable

Windows users are used to programs being a single .exe file that can be doubleclicked to run. We can produce that kind of user experience, targetting especially users that are less tech-savvy and e.g. have IE11 as their default browser which can be problematic.

An alternative may be us giving them a download link to our "app" program, which is basically a bundled Chrome that loads our web application URL on startup. The following is one of the many ways to get there:

Use nativefier to create a portable Chrome loading our web app. Ideally you should build on the target platform (Windows 7 or 10 in our case) Command may look like this:

$ nativefier --name=MyProject "https://myproject.com" --maximize --single-instance
# main.py
import sys, os

if getattr(sys, "frozen", False):
    bundle_dir = sys._MEIPASS
else:
    bundle_dir = os.path.dirname(os.path.abspath(__file__))

exe = os.path.join(bundle_dir, "MyProject.exe")
os.system(exe)
$ pip install virtualenv
$ virtualenv venv
$ venv\Scripts\activate
$ pip install pyinstaller
$ pyinstaller main.py --onefile --add-data="package";
all_bundled_up