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

查看:23
本文介绍了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 机器上工作,我正在使用带有 Python 3.4.3 的 WinPython 分发版.

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_*.dlllibiomp5md.dll 的文件复制到由 python setup 创建的 test.exe 所在的同一目录中.py build 是.在此之后,当按下 plot 按钮时,最小的 test.exe 显示了 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.

文件位于文件夹 libsite-packages umpycore.

The files were located in folder libsite-packages umpycore.

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

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