可执行构建闪烁并终止
Executable build flashes and terminates
我想 构建基于 Python 的简单 GUI 应用程序,可以分发给我的同事。在这个过程中,我了解了PySimpleGUI27 for Python 2.7 version.
以下是生成带有菜单选项的 window 的简单代码。然后我使用 PyInstaller 创建一个构建并测试它。但是,当我 运行 从 "dist" 文件夹构建 .exe 时,它只是闪烁并消失。但是当我从 Python IDE 中 运行 GUI 脚本时,我能够真正看到 GUI 功能。
import PySimpleGUI27 as sg
sg.ChangeLookAndFeel('LightGreen')
sg.SetOptions(element_padding=(0, 0))
# ------ Menu Definition ------ #
menu_def = [['File', ['Open', 'Save', 'Exit']],
['Edit', ['Paste', ['Special', 'Normal', ], 'Undo'], ],
['Help', 'About...'], ]
# ------ GUI Definition ------ #
layout = [
[sg.Menu(menu_def, )],
[sg.Output(size=(60, 20))]
]
window = sg.Window("Windows-like program", default_element_size=(12, 1), auto_size_text=False, auto_size_buttons=False,
default_button_element_size=(12, 1)).Layout(layout)
# ------ Loop & Process button menu choices ------ #
while True:
event, values = window.Read()
if event == None or event == 'Exit':
break
print('Button = ', event)
# ------ Process menu choices ------ #
if event == 'About...':
sg.Popup('About this program', 'Version: 1.0', 'PyDist: Anaconda27')
elif event == 'Open':
filename = sg.PopupGetFile('file to open', no_window=True)
print(filename)
我运行脚本时生成的GUI
当我尝试 运行 exe 文件时,它会闪烁并消失。请查看精彩的 GIF here。任何建议表示赞赏。
运行 使用 Powershell 从文件夹中提取 EXE。
PS C:\Users\user\AppData\Local\Continuum\anaconda3\envs\XCAL\Scripts\dist\PySimpleGUI_00> .\PySimpleGUI_00.exe
Traceback (most recent call last):
File "PySimpleGUI_00.py", line 1, in <module>
File "c:\users\user\appdata\local\temp\pip-install-qrr1qq\PyInstaller\PyInstaller\loader\pyimod03_importers.py", line 395, in load_module
File "site-packages\PySimpleGUI27\__init__.py", line 2, in <module>
File "c:\users\user\appdata\local\temp\pip-install-qrr1qq\PyInstaller\PyInstaller\loader\pyimod03_importers.py", line 395, in load_module
File "site-packages\PySimpleGUI27\PySimpleGUI27.py", line 13, in <module>
File "site-packages\future\standard_library\__init__.py", line 459, in install_aliases
ImportError: No module named UserList
[15328] Failed to execute script PySimpleGUI_00
除了使用 Python 3 到 运行 pyinstaller 之外,我建议使用 PySimpleGUI 库的 Python 3 版本。
运行 具有这些选项的 pyinstaller
pyinstaller -wF demo.py
你的例子应该是这个来使用普通的 PySimpleGUI 导入:
import PySimpleGUI as sg
sg.ChangeLookAndFeel('LightGreen')
sg.SetOptions(element_padding=(0, 0))
# ------ Menu Definition ------ #
menu_def = [['File', ['Open', 'Save', 'Exit']],
['Edit', ['Paste', ['Special', 'Normal', ], 'Undo'], ],
['Help', 'About...'], ]
# ------ GUI Definition ------ #
layout = [
[sg.Menu(menu_def, )],
[sg.Output(size=(60, 20))]
]
window = sg.Window("Windows-like program", default_element_size=(12, 1), auto_size_text=False, auto_size_buttons=False,
default_button_element_size=(12, 1)).Layout(layout)
# ------ Loop & Process button menu choices ------ #
while True:
event, values = window.Read()
if event == None or event == 'Exit':
break
print('Button = ', event)
# ------ Process menu choices ------ #
if event == 'About...':
sg.Popup('About this program', 'Version: 1.0', 'PyDist: Anaconda27')
elif event == 'Open':
filename = sg.PopupGetFile('file to open', no_window=True)
print(filename)
我想 构建基于 Python 的简单 GUI 应用程序,可以分发给我的同事。在这个过程中,我了解了PySimpleGUI27 for Python 2.7 version.
以下是生成带有菜单选项的 window 的简单代码。然后我使用 PyInstaller 创建一个构建并测试它。但是,当我 运行 从 "dist" 文件夹构建 .exe 时,它只是闪烁并消失。但是当我从 Python IDE 中 运行 GUI 脚本时,我能够真正看到 GUI 功能。
import PySimpleGUI27 as sg
sg.ChangeLookAndFeel('LightGreen')
sg.SetOptions(element_padding=(0, 0))
# ------ Menu Definition ------ #
menu_def = [['File', ['Open', 'Save', 'Exit']],
['Edit', ['Paste', ['Special', 'Normal', ], 'Undo'], ],
['Help', 'About...'], ]
# ------ GUI Definition ------ #
layout = [
[sg.Menu(menu_def, )],
[sg.Output(size=(60, 20))]
]
window = sg.Window("Windows-like program", default_element_size=(12, 1), auto_size_text=False, auto_size_buttons=False,
default_button_element_size=(12, 1)).Layout(layout)
# ------ Loop & Process button menu choices ------ #
while True:
event, values = window.Read()
if event == None or event == 'Exit':
break
print('Button = ', event)
# ------ Process menu choices ------ #
if event == 'About...':
sg.Popup('About this program', 'Version: 1.0', 'PyDist: Anaconda27')
elif event == 'Open':
filename = sg.PopupGetFile('file to open', no_window=True)
print(filename)
我运行脚本时生成的GUI
当我尝试 运行 exe 文件时,它会闪烁并消失。请查看精彩的 GIF here。任何建议表示赞赏。
运行 使用 Powershell 从文件夹中提取 EXE。
PS C:\Users\user\AppData\Local\Continuum\anaconda3\envs\XCAL\Scripts\dist\PySimpleGUI_00> .\PySimpleGUI_00.exe
Traceback (most recent call last):
File "PySimpleGUI_00.py", line 1, in <module>
File "c:\users\user\appdata\local\temp\pip-install-qrr1qq\PyInstaller\PyInstaller\loader\pyimod03_importers.py", line 395, in load_module
File "site-packages\PySimpleGUI27\__init__.py", line 2, in <module>
File "c:\users\user\appdata\local\temp\pip-install-qrr1qq\PyInstaller\PyInstaller\loader\pyimod03_importers.py", line 395, in load_module
File "site-packages\PySimpleGUI27\PySimpleGUI27.py", line 13, in <module>
File "site-packages\future\standard_library\__init__.py", line 459, in install_aliases
ImportError: No module named UserList
[15328] Failed to execute script PySimpleGUI_00
除了使用 Python 3 到 运行 pyinstaller 之外,我建议使用 PySimpleGUI 库的 Python 3 版本。
运行 具有这些选项的 pyinstaller
pyinstaller -wF demo.py
你的例子应该是这个来使用普通的 PySimpleGUI 导入:
import PySimpleGUI as sg
sg.ChangeLookAndFeel('LightGreen')
sg.SetOptions(element_padding=(0, 0))
# ------ Menu Definition ------ #
menu_def = [['File', ['Open', 'Save', 'Exit']],
['Edit', ['Paste', ['Special', 'Normal', ], 'Undo'], ],
['Help', 'About...'], ]
# ------ GUI Definition ------ #
layout = [
[sg.Menu(menu_def, )],
[sg.Output(size=(60, 20))]
]
window = sg.Window("Windows-like program", default_element_size=(12, 1), auto_size_text=False, auto_size_buttons=False,
default_button_element_size=(12, 1)).Layout(layout)
# ------ Loop & Process button menu choices ------ #
while True:
event, values = window.Read()
if event == None or event == 'Exit':
break
print('Button = ', event)
# ------ Process menu choices ------ #
if event == 'About...':
sg.Popup('About this program', 'Version: 1.0', 'PyDist: Anaconda27')
elif event == 'Open':
filename = sg.PopupGetFile('file to open', no_window=True)
print(filename)