按下绘图按钮后,cx_Freeze转换的GUI应用程序(tkinter)崩溃 [英] cx_Freeze converted GUI-app (tkinter) crashes after pressing plot button

查看:78
本文介绍了按下绘图按钮后,cx_Freeze转换的GUI应用程序(tkinter)崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经处理了好几天了,希望能有所帮助.我使用导入的模块tkinter,numpy,scipy,matplotlib开发了一个GUI应用程序,该模块在python本身中运行良好.转换为exe后,一切都会按预期进行,但matplotlib部分无法正常工作.当我按下定义的绘图按钮时,exe只是关闭而没有显示任何绘图. 因此,我想举一个最小的例子,我只绘制了一个sin函数,而我面临着同样的问题: 在python中工作完美,当将其转换为exe时,按下图按钮会崩溃.这是最小的示例:

I've been dealing with this for days now and hope to find some help. I developed a GUI-application with imported modules tkinter, numpy, scipy, matplotlib, which runs fine in python itself. After having converted to an exe everything works as expected, but NOT the matplotlib section. When I press my defined plot button, the exe simply closes and doesn't show any plots. So I thought to make a minimal example, where I simply plot a sin-function and I'm facing the same issue: Works perfect in python, when converting it to an exe it crashes when pressing the plot button. Here is the 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()

这是与cx_Freeze转换的对应的setup.py:

And here is my corresponding setup.py for converting with 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)

任何可能解决该问题的想法都受到高度赞赏.我正在使用64位Windows10计算机,并且正在将WinPython Distribution与Python 3.4.3结合使用.

Any ideas that might solve the issue are highly appreciated. I'm working on a 64-bit Windows10 machine and I'm using the WinPython Distribution with Python 3.4.3.

推荐答案

在使用相同的 test.py 测试PyInstaller时,我发现了该问题的潜在解决方案(或至少是一个解释).我收到有关缺少dll文件的错误消息,该文件为 mkl_intel_thread.dll .

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

我搜索了该文件,并在 numpy 文件夹中找到了该文件. 我将匹配 mkl _ *.dll libiomp5md.dll 的文件复制到了python setup.py build创建的 test.exe 所在的目录中.之后,最小的 test.exe 会在按下 plot 按钮时显示matplotlib窗口.

I searched for that file and it was found inside numpy folder. I copied files matching mkl_*.dll and also libiomp5md.dll to the same directory where the test.exe created by python setup.py build was. After this the minimal test.exe showed the matplotlib window when pressing the plot button.

文件位于文件夹 lib \ site-packages \ numpy \ core 中.

这篇关于按下绘图按钮后,cx_Freeze转换的GUI应用程序(tkinter)崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆