Bundling GTK3+ with py2exe
Asked Answered
U

2

5

Platform is Windows 7 64bit using python 2.7 and GTK3+ installed from http://sourceforge.net/projects/pygobjectwin32/files/?source=navbar

The exe is compiled but fails to run, due to this

The following modules appear to be missing
['gi.repository.Gdk', 'gi.repository.Gtk', 'overrides.registry']

How can i properly include these files?

imports in my .py file

from gi.repository import Gtk, Gdk

my setup file

#!/usr/bin/env python
from distutils.core import setup
import py2exe, sys
sys.path.append("C:\Python27\Lib\site-packages\gnome")
sys.path.append("C:\Python27\Lib\site-packages\repository")#tried including these extra dirs
sys.path.append("C:\Python27\Lib\site-packages\override")#tried including these extra dirs
sys.path.append("C:\Python27\Lib\site-packages\gi") #tried including these extra dirs

setup(
         options = {
                'py2exe': {
                            'bundle_files': 1,
                            #this does not work 'includes': ['Gtk']       
                            }
                },
console=["gui.py"],
zipfile=None
)

The executable error when ran:

ImportError: MemoryLoadLibrary failed loading gi\_gi.pyd

Thanks

Unsuccessful answered 8/1, 2014 at 17:26 Comment(0)
S
4

You need to add "gi" to "packages".

'options': {
    'py2exe': {
        'packages': 'gi',
    }
}
Sexism answered 19/1, 2014 at 20:33 Comment(0)
F
2

I haven't tested it on 64bit but this is the setup.py I've used to build with cx_freeze, py2exe looks like is not maintained for a long time.

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

## 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, "gtk")

## Collect the list of missing dll when cx_freeze builds the app
missing_dll = ['libgtk-3-0.dll',
               'libgdk-3-0.dll',
               'libatk-1.0-0.dll',
               'libcairo-gobject-2.dll',
               'libgdk_pixbuf-2.0-0.dll',
               'libjpeg-8.dll',
               'libpango-1.0-0.dll',
               'libpangocairo-1.0-0.dll',
               'libpangoft2-1.0-0.dll',
               'libpangowin32-1.0-0.dll',
               'libgnutls-26.dll',
               'libgcrypt-11.dll',
               'libp11-kit-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 = False,
    includes = ["gi"],
    packages = ["gi"],
    include_files = include_files
    )

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

Depending on the libraries you have used you might have to add some missing dll, look at the output of cx_freeze.

I've posted the same some time ago on gnome's wiki: https://wiki.gnome.org/Projects/PyGObject#Building_on_Win32_with_cx_freeze

Familist answered 8/1, 2014 at 22:2 Comment(5)
I have been playing with this to bundle my pyGObject application for windows, I have noticed that the entire working directory has grown from 50meg to 180meg (pygtk --> pygobject).Hoahoactzin
You can shrink that. I have gotten it downto about 56megHoahoactzin
Recommending another tool does not answer the question. py2exe is indeed actively maintained, and I have far more trouble with cx_freeze.Preview
@JasonMc92 thank you for your comment, if my comment is useless and you have a better solution with py2exe please feel free to post your code as I did.Familist
@gianmt, I'm still working on it, to be honest. (They're both incredibly hard to work with in my project.) I'm just letting you know that many on SE will not consider it good form to recommend another tool instead of answering the question. If you feel cx_freeze will work better, recommending it may indeed be helpful, but it is better as a comment or side-note in your answer, not as the entirety of your answer, as it takes the question off the unanswered list, lowering the chances of the actual question being solved.Preview

© 2022 - 2024 — McMap. All rights reserved.