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
- This gives us a folder with an executable and a whole bunch of other stuff like .dll files, not very convient yet.
- We can bundle this into a protable single executable for people to download and run.
- Of the many broken ways to do this on Windows I found this one to work. Assuming
packageis the directory created by
main.pya script as below:
- Download Python 2.7 (on 3.5, pyinstaller on Windows 10 has huge issues bundling builtin dll files)
- Create a main.py like below:
# 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)
- Install pyinstaller and run it against the script:
$ pip install virtualenv $ virtualenv venv $ venv\Scripts\activate $ pip install pyinstaller $ pyinstaller main.py --onefile --add-data="package;."
- This will produce
dist/main.exewhich is our single runnable executable. pyinstaller can also be used to add an icon file