尝试从具有GUI的简单程序执行可执行文件。 GUI是一个按钮,如果按下,则输出“Hello World”。 没有使用Pyinstaller打包它可以工作,但是当我打包它时,GUI在加载之前崩溃而没有任何输出。 我在Windows 10上使用Python34和最新的PyInstaller版本。
试图在调试模式下运行它,但没有从调试输出中产生任何内容。
我的简单GUI: my_gl.glade:
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<!-- interface-requires gtk+ 3.0 -->
<object class="GtkWindow" id="window1">
<property name="can_focus">False</property>
<signal name="destroy" handler="onDestroy" swapped="no"/>
<child>
<object class="GtkButton" id="button1">
<property name="label" translatable="yes">button</property>
<property name="use_action_appearance">False</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_action_appearance">False</property>
<signal name="pressed" handler="onButtonPressed" swapped="no"/>
</object>
</child>
</object>
</interface>
f.py:
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
class Handler:
def onDestroy(self, *args):
Gtk.main_quit()
def onButtonPressed(self, button):
print("Hello World!")
builder = Gtk.Builder()
builder.add_from_file("my_gl.glade")
builder.connect_signals(Handler())
print(1)
window = builder.get_object("window1")
print(2)
window.show_all()
Gtk.main()
我使用此命令构建: c:\ Python34 \ Scripts \ pyinstaller.exe --onedir --name = my --clean spec_gui.spec 使用以下spec文件: spec_gui.spec:
# -*- mode: python -*-
import os
import site
typelib_path = os.path.join(site.getsitepackages()[1], 'gnome', 'lib', 'girepository-1.0')
block_cipher = None
python_file_path = os.getcwd()
python_file = 'f.py' #change this
app_name = 'my' #change this
a = Analysis([python_file],
pathex=[python_file_path],
binaries=[(os.path.join(typelib_path, tl), 'gi_typelibs') for tl in os.listdir(typelib_path)],
datas=[],
hiddenimports=[],
hookspath=[],
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher)
#Add data files here
a.datas += [('my_gl.glade',r'my_gl.glade','DATA')]
pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)
exe = EXE(pyz,
a.scripts,
exclude_binaries=True,
name=app_name,
debug=1,
strip=False,
upx=True,
console=True )
coll = COLLECT(exe,
a.binaries,
a.zipfiles,
a.datas,
name=app_name,
debug=False,
strip=False,
upx=True,
console=True )