Feature #9635

Try building a Python/GI executable on windows

Added by alant 2015-06-22 07:45:09 . Updated 2015-08-24 07:06:35 .

Status:
Resolved
Priority:
Normal
Assignee:
Category:
Installation
Target version:
Start date:
2015-06-22
Due date:
% Done:

100%

Feature Branch:
Type of work:
Research
Starter:
Affected tool:
Installer
Deliverable for:

Description


Subtasks


History

#1 Updated by alant 2015-06-22 08:38:58

  • % Done changed from 0 to 50

I managed to create a native windows executable for a test Python/GI program under Windows 8.1

Downloads

Prepare

  • you need a Windows 8 (virtual) machine, with the files downloaded above
  • in Windows double-click python-3.4.3 and accept default choices but select “Install entire feature”
  • in Windows double-click pygi-aio-3.14.0-rev18-setup and choose to install only
    • GNOME libraries: GI, GTK, Pango (needed?)
    • non-GNOME libraraies: none
    • developpment files: GIR (needed?)
  • in Windows double-click cx_freeze-4.3.4.win32-py34 anc accept default choices

Test Program

main.py

import gi
from gi.repository import Gtk

dialog = Gtk.MessageDialog(None, Gtk.DialogFlags.DESTROY_WITH_PARENT, Gtk.MessageType.INFO, Gtk.ButtonsType.CLOSE, "Hello!")
dialog.run()
dialog.destroy()

Gtk.main()

setup.py

Result:

import os, site, sys
from cx_Freeze import setup, Executable

## Get the site-package folder, not everybody will install
## Python into C:\PythonXX
site_dir = site.getsitepackages()[1]
include_dll_path = os.path.join(site_dir, "gnome")

## Collect the list of missing dll when cx_freeze builds the app
## This list should be updated with the output of ListDLLs.exe
missing_dll = ['libffi-6.dll',
               'libgirepository-1.0-1.dll',
               'libglib-2.0-0.dll',
               'libgobject-2.0-0.dll',
               'libgio-2.0-0.dll',
               'libgmodule-2.0-0.dll',
               'libintl-8.dll',
               'libzzz.dll',
               'libwinpthread-1.dll',
               'libgtk-3-0.dll',
               'libgdk-3-0.dll',
               'libatk-1.0-0.dll',
               'libcairo-gobject-2.dll',
               'libgdk_pixbuf-2.0-0.dll',
               'libpango-1.0-0.dll',
               'libpangocairo-1.0-0.dll',
               'libpangowin32-1.0-0.dll',
               'libfontconfig-1.dll',
               'libfreetype-6.dll',
               'libpng16-16.dll',
               'libjasper-1.dll',
               'libjpeg-8.dll',
               'librsvg-2-2.dll',
               'libpangoft2-1.0-0.dll',
               'libwebp-5.dll',
               'libpangoft2-1.0-0.dll',
               'libxmlxpat.dll',
               'libharfbuzz-gobject-0.dll'
]

## We also need to add the glade folder, cx_freeze will walk
## into it and copy all the necessary files
glade_folder = 'glade'

## We need to add all the libraries too (for themes, etc..)
gtk_libs = ['etc', 'lib', 'share']

## Create the list of includes as cx_freeze likes
include_files = []
for dll in missing_dll:
    include_files.append((os.path.join(include_dll_path, dll), dll))

## Let's add glade folder and files
include_files.append((glade_folder, glade_folder))

## Let's add gtk libraries folders and files
for lib in gtk_libs:
    include_files.append((os.path.join(include_dll_path, lib), lib))

base = None

## Lets not open the console while running the app
if sys.platform == "win32":
    base = "Win32GUI"

executables = [
    Executable("main.py",
               base=base
    )
]

buildOptions = dict(
    compressed = True,
    includes = ["gi"],
    packages = ["gi"],
    include_files = include_files
    )

setup(
    name = "test_gtk3_app",
    author = "Alan",
    version = "1.0",
    description = "GTK 3 test",
    options = dict(build_exe = buildOptions),
    executables = executables
)

Build

  • start “Command Prompt”
  • cd Documents/test/
  • python setup.py bdist. Ihe resulting ZIP file lives in dist/. It is 37M big!
  • python setyp.py bdist_msi created a windows installer in dist/.

Test

  • extract the ZIP file
  • run main.exe
  • it works

Next steps

Other tools

#2 Updated by intrigeri 2015-06-22 10:11:49

  • Category set to Installation
  • Status changed from New to In Progress
  • Affected tool set to Installer

#3 Updated by intrigeri 2015-06-22 10:25:19

Great job! It’s a bit sad that this relies on the third-party pygobjectwin32, but oh well, perhaps we have no better option.

alant wrote:
> * extract the ZIP file
> * run main.exe
> * it works

If these steps were run on the same machine that had Python etc. installed already, then it would be good to try and run them again on a clean, fresh Windows installation that has no Python etc. installed. What do you think?

#4 Updated by alant 2015-06-24 15:10:34

> Great job! It’s a bit sad that this relies on the third-party pygobjectwin32, but oh well, perhaps we have no better option.

This pygobjectwin32 is in the downloads section of the official pygobject page: http://sourceforge.net/projects/pygobjectwin32/files/?source=navbar. I’m not aware of more official windows builds.

> If these steps were run on the same machine that had Python etc. installed already, then it would be good to try and run them again on a clean, fresh Windows installation that has no Python etc. installed. What do you think?

It works well on a fresh windows 8.1 with “Microsoft Visual C 2010 SP1 Redistributable Package (x86)” installed (https://www.microsoft.com/en-US/download/details.aspx?id=8328). I guess we may bundle this DLL but don’t know how legal it would be…

#5 Updated by intrigeri 2015-06-27 01:36:53

  • QA Check set to Info Needed

>> It’s a bit sad that this relies on the third-party pygobjectwin32, but oh well, perhaps we have no better option.

> This pygobjectwin32 is in the downloads section of the official pygobject page: http://sourceforge.net/projects/pygobjectwin32/files/?source=navbar.

That’s the homepage of the pygobjectwin32 project, not the one of pygobject.

> It works well on a fresh windows 8.1 with “Microsoft Visual C 2010 SP1 Redistributable Package (x86)” installed (https://www.microsoft.com/en-US/download/details.aspx?id=8328). I guess we may bundle this DLL but don’t know how legal it would be…

And without that Visual C thing?

#6 Updated by alant 2015-06-27 15:01:47

intrigeri wrote:
> >> It’s a bit sad that this relies on the third-party pygobjectwin32, but oh well, perhaps we have no better option.
>
> > This pygobjectwin32 is in the downloads section of the official pygobject page: http://sourceforge.net/projects/pygobjectwin32/files/?source=navbar.
>
> That’s the homepage of the pygobjectwin32 project, not the one of pygobject.
>
Sorry I meant https://wiki.gnome.org/Projects/PyGObject#Downloads

> > It works well on a fresh windows 8.1 with “Microsoft Visual C 2010 SP1 Redistributable Package (x86)” installed (https://www.microsoft.com/en-US/download/details.aspx?id=8328). I guess we may bundle this DLL but don’t know how legal it would be…
>
> And without that Visual C thing?

It fails with an error message like “missing DLL”.

Good news is that it looks OK to bundle it: https://msdn.microsoft.com/en-us/library/8kche8ah.aspx

#7 Updated by intrigeri 2015-06-28 04:00:47

> Sorry I meant https://wiki.gnome.org/Projects/PyGObject#Downloads

OK, thanks. That’s convincing enough, I think.

>> And without that Visual C thing?

> It fails with an error message like “missing DLL”.

> Good news is that it looks OK to bundle it: https://msdn.microsoft.com/en-us/library/8kche8ah.aspx

Cool :)

=> I’m now convinced that moving to GTK is the way to go. Thanks again!

May you please copy the relevant bits of this ticket to a new blueprint dedicated to Feature #8558, and then close this very ticket as resolved?

#8 Updated by intrigeri 2015-07-11 08:22:50

#9 Updated by alant 2015-08-24 07:06:35

  • Status changed from In Progress to Resolved
  • Assignee deleted (alant)
  • % Done changed from 50 to 100
  • QA Check deleted (Info Needed)
  • Blueprint set to https://tails.boum.org/blueprint/Port_Tails_Installer_to_Windows/