I have been doing this for several days now and hope to find help. I developed a GUI application with imported modules tkinter, numpy, scipy, matplotlib, which works fine in Python itself. After conversion to exe, everything works as expected, but NOT in the matplotlib section. When I press the button for a specific schedule, the executable simply closes and does not show any graphs. Therefore, I decided to make a minimal example, where I just draw the sin function and encounter the same problem: it works fine in python, when converting it to exe, it crashes when the plot button is pressed. Here is a minimal example:
import tkinter as tk import matplotlib.pyplot as plt import numpy as np class MainWindow(tk.Frame): def __init__(self): tk.Frame.__init__(self,bg='#9C9C9C',relief="flat", bd=10) self.place(width=x,height=y) self.create_widgets() def function(self): datax = np.arange(-50,50,0.1) datay = np.sin(datax) plt.plot(datax,datay) plt.show() def create_widgets(self): plot = tk.Button(self, text='PLOT', command=self.function) plot.pack() x,y=120,300 root=tk.Tk() root.geometry(str(x)+"x"+str(y)) app = MainWindow() app.mainloop()
And here is my corresponding setup.py for conversion using cx_Freeze:
import cx_Freeze import matplotlib import sys import numpy import tkinter base = None if sys.platform == "win32": base = "Win32GUI" executables = [cx_Freeze.Executable("test.py", base=base)] build_exe_options = {"includes": ["matplotlib.backends.backend_tkagg","matplotlib.pyplot", "tkinter.filedialog","numpy"], "include_files":[(matplotlib.get_data_path(), "mpl-data")], "excludes":[], } cx_Freeze.setup( name = "test it", options = {"build_exe": build_exe_options}, version = "1.0", description = "I test it", executables = executables)
Any ideas that can solve the problem are much appreciated. I work on a 64-bit machine with Windows10 and use the WinPython distribution with Python 3.4.3.