Converted cx_Freeze GUI application (tkinter) crashes after clicking the build button

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.

+8
source share
5 answers

I found a potential solution (or at least an explanation) of this problem when testing PyInstaller with the same test.py. I received an error message about a missing dll file, this mkl_intel_thread.dll file.

I searched for this file and it was found inside the numpy folder. I copied the files matching mkl _ *. Dll , as well as libiomp5md.dll in the same directory where test.exe was created, created by python setup.py build . After that, the minimal test.exe showed the matplotlib window when the plot button was clicked.

The files were located in the lib \ site-packages \ numpy \ core folder.

+26
source

I really wanted to post this as a comment, but I have no reputation. This is basically a continuation of JJ Hakala who will answer how to find the reason.

If you change the base to "Console", that is, using

  base = "Console" 

but not

  base = "Win32GUI" 

the console will also appear when the program starts, and this error will be printed

  Intel MKL FATAL ERROR: Cannot load mkl_intel_thread.dll. 

Which can help find the cause of the problem quite quickly.

I thought it was worth mentioning, as this trick can also be useful for diagnosing other problems. In the final version, you can return to Win32GUI to avoid an additional console. I have to provide loans to this other fooobar.com/questions/1240670 / ...

+5
source

I followed @JJ Hakala's answer , but found that there was no need to copy all mkl _ * files. Dll and libiomp5md.dll. For me, this worked with libiomp5md.dll mkl_core.dll mkl_def.dll mkl_intel_thread.dll. This helps reduce the final packet size by ~ 500 MB.

You can also include the files you want to copy in the include_files option. You can also enable them only if sys.platform is win32 .

I use Anaconda as well as @Matt Williams , so changing the OP code a bit:

 import cx_Freeze import matplotlib import sys import numpy import tkinter import os PYTHON_INSTALL_DIR = os.path.dirname(os.path.dirname(os.__file__)) build_exe_options = {"includes": ["matplotlib.backends.backend_tkagg","matplotlib.pyplot", "tkinter.filedialog","numpy"], "include_files":[(matplotlib.get_data_path(), "mpl-data")], "excludes":[], } base = None if sys.platform == "win32": base = "Win32GUI" DLLS_FOLDER = os.path.join(PYTHON_INSTALL_DIR, 'Library', 'bin') dependencies = ['libiomp5md.dll', 'mkl_core.dll', 'mkl_def.dll', 'mkl_intel_thread.dll'] for dependency in dependencies: build_exe_options['include_files'].append(os.path.join(DLLS_FOLDER, dependency)) executables = [cx_Freeze.Executable("test.py", base=base)] cx_Freeze.setup( name = "test it", options = {"build_exe": build_exe_options}, version = "1.0", description = "I test it", executables = executables) 
+2
source

Check if you have the numpy + mkl package installed. Removing numpy and installing the numpy + mkl package solved my problem of getting mkl_intel_thread.dll related error

0
source

Tried to reinstall NumPy this does not work anyway. It was decided to copy / by mkl_intel_thread.dll to the root directory of my app.exe

0
source

All Articles