Python pyinstaller不能与tkinter和matplotlib一起使用

Python pyinstaller不能与tkinter和matplotlib一起使用,python,matplotlib,tkinter,pyinstaller,Python,Matplotlib,Tkinter,Pyinstaller,我有蟒蛇,蟒蛇3。我从Anaconda启动cmd.exe并运行代码: pyinstaller--onefile guitest4.py。 报告了大量错误,生成了exe,exe启动cmd窗口并立即关闭。 将代码编译成exe(包含tkinter的代码)效果很好。但是,每当我包含matplotlib时,都会出现问题。有什么想法吗?谢谢 输出: 如果我将-w选项添加到pyinstaller中,则会从 守则: from matplotlib.backends.backend_tkagg import (

我有蟒蛇,蟒蛇3。我从Anaconda启动cmd.exe并运行代码:
pyinstaller--onefile guitest4.py
。 报告了大量错误,生成了exe,exe启动cmd窗口并立即关闭。 将代码编译成exe(包含tkinter的代码)效果很好。但是,每当我包含matplotlib时,都会出现问题。有什么想法吗?谢谢

输出:

如果我将-w选项添加到pyinstaller中,则会从

守则:

from matplotlib.backends.backend_tkagg import (
    FigureCanvasTkAgg, NavigationToolbar2Tk)
# Implement the default Matplotlib key bindings.
from matplotlib.backend_bases import key_press_handler
from matplotlib.figure import Figure

import numpy as np


root = tkinter.Tk()
root.wm_title("Embedding in Tk")

fig = Figure(figsize=(5, 4), dpi=100)
t = np.arange(0, 3, .01)
fig.add_subplot(111).plot(t, 2 * np.sin(2 * np.pi * t))

canvas = FigureCanvasTkAgg(fig, master=root)  # A tk.DrawingArea.
canvas.draw()
canvas.get_tk_widget().pack(side=tkinter.TOP, fill=tkinter.BOTH, expand=1)

toolbar = NavigationToolbar2Tk(canvas, root)
toolbar.update()
canvas.get_tk_widget().pack(side=tkinter.TOP, fill=tkinter.BOTH, expand=1)


def on_key_press(event):
    print("you pressed {}".format(event.key))
    key_press_handler(event, canvas, toolbar)


canvas.mpl_connect("key_press_event", on_key_press)


def _quit():
    root.quit()     # stops mainloop
    root.destroy()  # this is necessary on Windows to prevent
                    # Fatal Python Error: PyEval_RestoreThread: NULL tstate


button = tkinter.Button(master=root, text="Quit", command=_quit)
button.pack(side=tkinter.BOTTOM)

tkinter.mainloop()
# If you put root.destroy() here, it will cause an error if the window is
# closed with the window manager.

该问题通过auto py to exe gui解决。除了我使用pyinstaller所做的之外,它还能做些什么我不知道,但它可以工作。

为什么要从基本环境运行pyinstaller?康达就是这么用的吗?此外,除非绝对必要,否则请不要以图像形式共享信息。请参阅:,。如果没有使用matplotlib,它与conda的配合效果很好,所以我想是的,它应该可以工作。我有点失望,没有人发布解决方案。它在基本环境中尝试pyinstaller时报告了相同的情况。因此,这不是问题所在。