我有一个简单的PyGObject应用程序:
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()
我正在尝试使用cx_freeze在Linux上使用以下setup.py
脚本冻结它:
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,
)]
)
我正在运行它:python3 setup_pygobject.py build
当我尝试运行冻结的应用程序时,收到以下错误消息:
(process:22538): Gtk-CRITICAL **: gtk_settings_get_for_screen: assertion 'GDK_IS_SCREEN (screen)' failed
Segmentation fault (core dumped)
我可能在目录中缺少一堆库,例如they have explained for Windows。我已经尝试pmap
找到丢失的库。作为最后的手段,我还尝试将/usr/lib64/
中的所有库(以及其他一些我不记得的)复制到工作目录中。
有一种很好的方法可以找到我需要的库或更好的解决方法吗?
相关问题,但对于Windows: Python3 + PyGobject + GTK3 and cx_freeze missing DLLs
修改
我尝试使用dbg
来调查核心转储。我明白了:
...
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
当我安装单独的debuginfos时,我得到了这个:
...
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;
通过gdb
运行应用程序时,我得到了这个:
...
(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;
堆栈追踪:
(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 ()
编辑2:
相关套餐:
python3.x86_64 3.4.2-6.fc22
python3-gobject.x86_64 3.16.2-1.fc22
cx-Freeze (4.3.4)
答案 0 :(得分:2)
所以问题不在于缺少库(因为它们在路径中)但在setup.py
脚本中缺少包。正确的设置如下:
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,
)]
)