python --> pyinstaller - .exe 文件将 return "test returned -1"
python --> pyinstaller - .exe file will return "test returned -1"
[1]
代码是:
import Tkinter
from Tkinter import *
# Create Tk instance
root = Tkinter.Tk(className="test")
# Open Notepad
def openNotepad():
import pywinauto
app = pywinauto.Application.start("notepad.exe")
# Add menu
menu = Menu(root)
root.config(menu=menu)
filemenu = Menu(menu)
menu.add_cascade(label="01 File", menu=filemenu)
filemenu.add_command(label="New", command=openNotepad)
# Pack all
root.mainloop()
[2]
如果我双击 .py 文件,代码就可以工作。
如果我只留下 openNotepad() 函数,那么 .exe 就可以了。
根据文档:https://github.com/pyinstaller/pyinstaller/wiki/Supported-Packages,支持 pywinauto 库。
如果我只留下 Tkinter 片段,.exe 将起作用。
因此,请分享我做错了什么,或者请为 python 2.7x 推荐其他 python 安装程序。
通过注释掉开头的行:excludedimports in files \PyInstaller\hooks\hook-PIL.py and hook-PIL.SpiderImagePlugin.py,问题就解决了。
尝试将每个 exit()
、quit()
或 os._exit()
替换为 sys.exit()
。
我看到您的代码中没有任何这些,但其他人可能会发现此建议很有用。
我的版本:python3.4,pyinstaller3.1.1
[1] 代码是:
import Tkinter
from Tkinter import *
# Create Tk instance
root = Tkinter.Tk(className="test")
# Open Notepad
def openNotepad():
import pywinauto
app = pywinauto.Application.start("notepad.exe")
# Add menu
menu = Menu(root)
root.config(menu=menu)
filemenu = Menu(menu)
menu.add_cascade(label="01 File", menu=filemenu)
filemenu.add_command(label="New", command=openNotepad)
# Pack all
root.mainloop()
[2] 如果我双击 .py 文件,代码就可以工作。
如果我只留下 openNotepad() 函数,那么 .exe 就可以了。
根据文档:https://github.com/pyinstaller/pyinstaller/wiki/Supported-Packages,支持 pywinauto 库。
如果我只留下 Tkinter 片段,.exe 将起作用。
因此,请分享我做错了什么,或者请为 python 2.7x 推荐其他 python 安装程序。
通过注释掉开头的行:excludedimports in files \PyInstaller\hooks\hook-PIL.py and hook-PIL.SpiderImagePlugin.py,问题就解决了。
尝试将每个 exit()
、quit()
或 os._exit()
替换为 sys.exit()
。
我看到您的代码中没有任何这些,但其他人可能会发现此建议很有用。
我的版本:python3.4,pyinstaller3.1.1