Using GitHub Actions to bundle python application into a single exe and automatic release ⚡

Anshuman Fauzdar
3 min readJun 20, 2021

Packing your python application into single executable exe can be very useful in situation like showing to your friends or simply sharing as useful application which is click and play!

How to begin?

Make sure your python application works smoothly and all dependencies are mentioned in requirements.txt

  • Install pyinstaller using pip
  • Inside your project folder run pyinstaller with this command
  • SPEC file will be created and your exe will be in dist folder, run and verify its working as intended
  • You can modify SPEC file to add icon to your exe, place .ico in same folder and add this in last line of SPEC file

GitHub Actions

Now your python application is packed into single exe with your desired icon and run smoothly!

But… how to automate this stuff and upload as release on GitHub?

GitHub Actions is a powerful tool and solves this problem easily:

  • There are multiple options available on actions marketplace but I used crude way of making this action
  • Make .github/workflows subfolders in your project folder and make a YML file

Lets look at stepwise explanation for this process:

  • Checkout

This step check outs repo and make sure everything is synced and up to mark

  • Install Python

This steps install python in my example 3.7 x64

  • Install requirements

This installs requirements for your python application

  • Run pyinstaller

SPEC file is named same as your main python file which you packed using pyinstaller

  • upload-artifact

This uploads artifacts from your workflow allowing you to share data between jobs and store data once a workflow is complete

  • create release

secrets.GITHUB_TOKEN is automatically parsed

tag_name and release_name are set to latest commit message [follow naming considerations otherwise this step will fail], or modify according to your need read this

Other parameters are optional and can be set according to requirement

  • upload release asset

This uploads your packed exe as asset in release!

Final Result

Your release will look like this

and in case of exe it will show Windows protected your PC blue screen, click on more info and run anyway

Finally you can enjoy your exe application!

My sample application:

I hope this guide will help to setup your python application workflow and share exe with everyone without installing any dependency!

--

--

Anshuman Fauzdar

BTech Mechatronics | Embedded Engineer | Software and Hardware Integrator | anshumanfauzdar.me | Open Source projects maintained on github.com/AnshumanFauzdar