How to create installers for your Python application?🤔

Requirements

  1. Debian operating system.
  2. Windows operating system with Python 3, pip and inno setup installed.

Creating inno setup installer (on windows)

In order to create an installer, we must convert the application script to executable. We can do this using pyinstaller.

Step 1: create a directory my_app.

Step 2: Create a new file my_app/app.py and copy the following contents to it:

import tkinter as tk

root = tk.Tk()
tk.Label(master=root, text="Hello world", font=("Arial", 30)).pack()
root.mainloop()

Step 3: Navigate to my_app directory and run the following command in CMD:

pip install pyinstaller  
pyinstaller --onefile app.py -w

Step 4: Wait for the command to complete and open inno setup compiler.

Step 5: On the inno setup welcome screen, click "Create a new script file using the Script Wizard" and hit ok.

Step 6: Follow on screen instructions (main executable file is in my_app/dist/app.exe).

Step 7: Compile the script and done!

Creating deb package (On Debian OS)

Just like windows, we must create an executable from our script for deb package.

Step 1: Create a directory my_app

Step 2: Create a new file my_app/app.py and copy the following contents to it:

import tkinter as tk

root = tk.Tk()
tk.Label(master=root, text="Hello world", font=("Arial", 30)).pack()
root.mainloop()

Step 3: Navigate to my_app directory and run the following command in terminal:

pip install pyinstaller
pyinstaller app.py -w

Step 4: wait for it to complete and create the following directories.

my-app_1.0.0/DEBIAN
my-app_1.0.0/my_app
my-app_1.0.0/usr/share/applications

Step 5: Create a file my-app_1.0.0/DEBIAN/control and copy the following contents into it.

Package: my-app
Version: 1.0.0
Architecture: all
Maintainer: [Your name]
Copyright: [year] [Your name]
License: MIT
Homepage: [homepage url]
Description: My deb package.

Step 6: Create a file my-app_1.0.0/usr/share/applications/my-app.desktop and copy the following contents into it.

[Desktop Entry]
Type=Application
Exec=/my_app/app
Hidden=false
NoDisplay=false
Name=My app
Comment=My app.

Step 7: Copy all files and folders from my_app/dist to my-app_1.0.0/my_app

Step 8: navigate to the parent directory of my-app_1.0.0 and execute the following command:

dpkg-deb --build my-app_1.0.0

Step 9: Wait for it to complete and done! You will find a deb package named my-app_1.0.0.deb

Thank you!

34