Skip to main content
 首页 » 编程设计

python --> pyinstaller之.exe 文件将返回 "test returned -1"

2025年05月04日27insus

[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 安装程序。

请您参考如下方法:

通过在文件\PyInstaller\hooks\hook-PIL.py 和 hook-PIL.SpiderImagePlugin.py 中注释掉开头为:excludedimports 的行,问题就解决了。