Nuitka打包python,加 --windows-disable-console 选项后报错。
经过半天排查,终于查明是因为中文字符问题。(我没有使用中文,只是print的信息中有个中文感叹号,所以大大增加了我排查时间。 )
排查问题,从console看报错信息肯定是第一选择啊,但在console中这丫又好好的正常的,加了 --windows-disable-console 又不行了,这又增加了排查时间。最后只能把捕捉到错误信息保存到文本里面,才找到原因。
上代码:
import tkinter as tk
def test():
print('HELLO WORLD')
lblMsg["text"] = 'HELLO WORLD 打印成功'
def test2():
try:
print('世界你好')
except:
lblMsg["text"] = '捕捉到err'
else:
lblMsg["text"] = '世界你好 打印成功'
def test3():
print('世界你好')
lblMsg["text"] = 'I AM OK'
win=tk.Tk()
win.geometry("300x300")
lblMsg=tk.Label(win,text="test")
lblMsg.place(x=50,y=50)
tk.Button(win,text="print HELLO WORLD",command=test).place(x=100,y=100)
tk.Button(win,text="try 世界你好",command=test2).place(x=100,y=150)
tk.Button(win,text="no try世界你好",command=test3).place(x=100,y=200)
win.mainloop()
以上代码在如果用pyinstaller打包,有没有--noconsole 选项,功能都正常!
用Nuitka打包,不带--windows-disable-console 是正常的, 加上 --windows-disable-console 就不正常了。