Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cx_freeze PyGObject application on Linux

I have a simple PyGObject application:

from gi.repository import Gtk


class Window(Gtk.Window):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.set_border_width(5)

        self.button = Gtk.Button('Test')

        self.box = Gtk.Box()
        self.box.pack_start(self.button, True, True, 0)

        self.add(self.box)
        self.connect('delete-event', Gtk.main_quit)
        self.show_all()


win = Window()
Gtk.main()

I am trying to freeze it using cx_freeze on Linux using following setup.py script:

from cx_Freeze import setup, Executable

setup(name="GUI Test",
      description="GUITest",
      version="0.1",
      options={"build_exe": {"build_exe": "Bin/pygobject",
                             "create_shared_zip": False,
                             }},
      executables=[Executable(script="hello_pygobject.py",
                              targetName="hello",
                              appendScriptToExe=True,
                              )]
      )

And I am running it like this: python3 setup_pygobject.py build

When I try to run the frozen application, I get the following error message:

(process:22538): Gtk-CRITICAL **: gtk_settings_get_for_screen: assertion 'GDK_IS_SCREEN (screen)' failed
Segmentation fault (core dumped)

I am probably missing a bunch of libraries in the directory, such as they have explained for Windows. I have tried pmap to find missing libraries. As a last resort I have also tried to copy all libraries in /usr/lib64/ (+some others I do not remember) to the working directory.

Is there a good way how to find which libraries I need or some better way to fix it?

Related question, but for Windows: Python3 + PyGobject + GTK3 and cx_freeze missing DLLs

EDIT:

I tried to use dbg to investigate core dump. I got this:

...
Core was generated by `./hello'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0  0x00007fd3d009d4ef in _gtk_settings_get_style_cascade () from /lib64/libgtk-3.so.0

When I installed separate debuginfos I got this:

...
Core was generated by `./hello'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0  _gtk_settings_get_style_cascade (settings=0x0, scale=scale@entry=1) at gtksettings.c:1764
1764      GtkSettingsPrivate *priv = settings->priv;

When running the application through gdb I got this:

...
(process:21699): Gtk-CRITICAL **: gtk_settings_get_for_screen: assertion 'GDK_IS_SCREEN (screen)' failed

Program received signal SIGSEGV, Segmentation fault.
_gtk_settings_get_style_cascade (settings=0x0, scale=scale@entry=1) at gtksettings.c:1764
1764      GtkSettingsPrivate *priv = settings->priv;

Stack trace:

(gdb) backtrace
#0  0x00007fffed62c4ef in _gtk_settings_get_style_cascade (settings=0x0, scale=scale@entry=1) at gtksettings.c:1764
#1  0x00007fffed6422d0 in gtk_style_context_init (style_context=0x904080 [GtkStyleContext]) at gtkstylecontext.c:425
#2  0x00007fffef86556b in g_type_create_instance (type=9442240) at gtype.c:1870
#3  0x00007fffef8480ab in g_object_new_internal (class=class@entry=0x901490, params=params@entry=0x0, n_params=n_params@entry=0) at gobject.c:1774
#4  0x00007fffef849991 in g_object_newv (object_type=object_type@entry=9442240, n_parameters=n_parameters@entry=0, parameters=parameters@entry=0x0) at gobject.c:1921
#5  0x00007fffef84a2c4 in g_object_new (object_type=9442240, first_property_name=first_property_name@entry=0x0) at gobject.c:1614
#6  0x00007fffed63f709 in gtk_style_context_new () at gtkstylecontext.c:994
#7  0x00007fffed46086f in _gtk_style_new_for_path (screen=0x0, path=path@entry=0x83dd70) at deprecated/gtkstyle.c:853
#8  0x00007fffed4608ee in gtk_style_new () at deprecated/gtkstyle.c:887
#9  0x00007fffed463569 in gtk_widget_get_default_style () at deprecated/gtkstyle.c:4057
#10 0x00007fffed6dfde5 in gtk_widget_init (widget=<optimized out>) at gtkwidget.c:4510
#11 0x00007fffef865527 in g_type_create_instance (type=9319840) at gtype.c:1864
#12 0x00007fffef8480ab in g_object_new_internal (class=class@entry=0x900b90, params=params@entry=0x0, n_params=n_params@entry=0) at gobject.c:1774
#13 0x00007fffef849991 in g_object_newv (object_type=9319840, n_parameters=0, parameters=0x0) at gobject.c:1921
#14 0x00007fffefece19c in pygobject_constructv () at /home/skontar/Python/Examples/GUI/Bin/pygobject/gi._gi.so
#15 0x00007fffefed57c1 in pygobject_init () at /home/skontar/Python/Examples/GUI/Bin/pygobject/gi._gi.so
#16 0x00007ffff79fec4c in wrap_init () at /home/skontar/Python/Examples/GUI/Bin/pygobject/libpython3.4m.so.1.0
#17 0x00007ffff79adf31 in PyObject_Call () at /home/skontar/Python/Examples/GUI/Bin/pygobject/libpython3.4m.so.1.0
#18 0x00007ffff7a60a9f in PyEval_EvalFrameEx () at /home/skontar/Python/Examples/GUI/Bin/pygobject/libpython3.4m.so.1.0
#19 0x00007ffff7a65de6 in PyEval_EvalCodeEx () at /home/skontar/Python/Examples/GUI/Bin/pygobject/libpython3.4m.so.1.0
#20 0x00007ffff79d65f8 in function_call () at /home/skontar/Python/Examples/GUI/Bin/pygobject/libpython3.4m.so.1.0
#21 0x00007ffff79adf31 in PyObject_Call () at /home/skontar/Python/Examples/GUI/Bin/pygobject/libpython3.4m.so.1.0
#22 0x00007ffff79c3344 in method_call () at /home/skontar/Python/Examples/GUI/Bin/pygobject/libpython3.4m.so.1.0
#23 0x00007ffff79adf31 in PyObject_Call () at /home/skontar/Python/Examples/GUI/Bin/pygobject/libpython3.4m.so.1.0
#24 0x00007ffff7a057e0 in slot_tp_init () at /home/skontar/Python/Examples/GUI/Bin/pygobject/libpython3.4m.so.1.0
#25 0x00007ffff7a03276 in type_call () at /home/skontar/Python/Examples/GUI/Bin/pygobject/libpython3.4m.so.1.0
#26 0x00007ffff79adf31 in PyObject_Call () at /home/skontar/Python/Examples/GUI/Bin/pygobject/libpython3.4m.so.1.0
#27 0x00007ffff7a5de0a in PyEval_EvalFrameEx () at /home/skontar/Python/Examples/GUI/Bin/pygobject/libpython3.4m.so.1.0
#28 0x00007ffff7a65de6 in PyEval_EvalCodeEx () at /home/skontar/Python/Examples/GUI/Bin/pygobject/libpython3.4m.so.1.0
#29 0x00007ffff7a65e8b in PyEval_EvalCode () at /home/skontar/Python/Examples/GUI/Bin/pygobject/libpython3.4m.so.1.0
#30 0x00007ffff7a5936a in builtin_exec () at /home/skontar/Python/Examples/GUI/Bin/pygobject/libpython3.4m.so.1.0
#31 0x00007ffff7a64f1f in PyEval_EvalFrameEx () at /home/skontar/Python/Examples/GUI/Bin/pygobject/libpython3.4m.so.1.0
#32 0x00007ffff7a65de6 in PyEval_EvalCodeEx () at /home/skontar/Python/Examples/GUI/Bin/pygobject/libpython3.4m.so.1.0
#33 0x00007ffff7a65e8b in PyEval_EvalCode () at /home/skontar/Python/Examples/GUI/Bin/pygobject/libpython3.4m.so.1.0
#34 0x000000000040192c in  ()
#35 0x00007ffff738f700 in __libc_start_main (main=0x4011e0, argc=1, argv=0x7fffffffe598, init=<optimized out>, fini=<optimized out>, rtld_fini=<optimized out>, stack_end=0x7fffffffe588)
    at libc-start.c:289
#36 0x0000000000401c69 in  ()

EDIT 2:

Relevant packages:

python3.x86_64            3.4.2-6.fc22
python3-gobject.x86_64    3.16.2-1.fc22   

cx-Freeze (4.3.4)
like image 449
Fenikso Avatar asked Sep 18 '15 09:09

Fenikso


1 Answers

So the problem was not in missing libraries (as they were in the path anyway) but missing package in setup.py script. The correct setup is as follows:

from cx_Freeze import setup, Executable

setup(name="GUI Test",
      description="GUITest",
      version="0.1",
      options={"build_exe": {"build_exe": "Bin/pygobject",
                             "create_shared_zip": False,
                             "packages": ["gi"],
                             }},
      executables=[Executable(script="hello_pygobject.py",
                              targetName="hello",
                              appendScriptToExe=True,
                              )]
      )
like image 194
Fenikso Avatar answered Nov 04 '22 04:11

Fenikso