Creating an Installer for Linux Application

Best approach to writing a generic installer for a Linux application?

Instead of the installer approach, I think a better way than having a single script that does it at install time is to have a build system which generates .deb or .rpm files suitable for installation on each system you have to support.

A poor man's way of going at that might be to use checkinstall, which creates packages from the files installed via 'make install'. So you'd build your app on each system and have the package magically created in the distro's native format.

Creating an installer for a python GTK3 application

After a few days of searching the internet for a solution, I have finally stumbled upon this blog-post, that helped me to create an .exe to run the program on Windows, which was my main goal.

For future reference, these were the steps I took:

  • Make sure you have Python installed, with GTK+3 (install from here) and PyGObject (install from here) installed. IMPORTANT: When installing PyGObject, make sure you select both Gtk+ AND Gstreamer (for some reason you must have it for py2exe to get all the dlls)

  • At the same directory as your project, create a new python file containing the following script. Make sure that you change 'main.py' to the name of your own main script file (the one that launches your App):


setup.py:

from distutils.core import setup 
import py2exe
import sys, os, site, shutil

site_dir = site.getsitepackages()[1]
include_dll_path = os.path.join(site_dir, "gnome")

gtk_dirs_to_include = ['etc', 'lib\\gtk-3.0', 'lib\\girepository-1.0', 'lib\\gio', 'lib\\gdk-pixbuf-2.0', 'share\\glib-2.0', 'share\\fonts', 'share\\icons', 'share\\themes\\Default', 'share\\themes\\HighContrast']

gtk_dlls = []
tmp_dlls = []
cdir = os.getcwd()
for dll in os.listdir(include_dll_path):
if dll.lower().endswith('.dll'):
gtk_dlls.append(os.path.join(include_dll_path, dll))
tmp_dlls.append(os.path.join(cdir, dll))

for dll in gtk_dlls:
shutil.copy(dll, cdir)

# -- change main.py if needed -- #
setup(windows=['main.py'], options={
'py2exe': {
'includes' : ['gi'],
'packages': ['gi']
}
})

dest_dir = os.path.join(cdir, 'dist')

if not os.path.exists(dest_dir):
os.makedirs(dest_dir)

for dll in tmp_dlls:
shutil.copy(dll, dest_dir)
os.remove(dll)

for d in gtk_dirs_to_include:
shutil.copytree(os.path.join(site_dir, "gnome", d), os.path.join(dest_dir, d))

  • Run setup.py, preferably from command line by typing python setup.py py2exe, and it will create two new directories in your project's folder: \build and \dist. The \dist folder is the one we care about, in which you will find all the essential Dlls, and your program's newly created .exe, named after your main python script (main.exe in my case).

  • Important Additional Note: if you are using any non-python file in your project (css file in my case) be sure to copy and paste it to the \dist directory, or the app won't be able to find it!


As far as I'm aware of this solution only work for distributing for Windows (which was my main goal), but in the future I am going to try and do the same for Linux and OSX, and I'll update the answer accordingly



Related Topics



Leave a reply



Submit