2016-01-15 30 views
5

我一直在处理这个好几天了,希望能找到一些帮助。我开发了一个带有导入模块tkinter,numpy,scipy,matplotlib的GUI应用程序,它在Python本身中运行良好。转换为* .exe后,所有内容都按预期工作,但不是matplotlib部分。当我按下我定义的绘图按钮时,* .exe只是简单地关闭并且不显示任何绘图。 所以我想做一个简约的例子,在那里我简单地绘制一个sin函数,并且我面临同样的问题: 在python中完美工作时,将其转换为* .exe时,按下plot按钮时崩溃。简约的例子在这里:cx_freeze转换后的GUI应用程序(tkinter)崩溃后按剧情按钮

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() 

并看到我的相应的“setup.py”与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发行版和Python 3.4.3。

+0

知道这个问题是否与Windows 10相关,或者是否与其他Windows版本相同,将会很有趣。 –

+0

啊,对不起,我忘了提及它。在Windows 7,64位机器上发生同样的WinPython分发问题。 – PuseMuckeL

+0

刚刚在32位XP上试过这个没有问题,我会在64位win7以后尝试它 –

回答

19

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

我搜索了该文件,它被发现在numpy文件夹中。 我复制的文件匹配MKL _ *。dll的libiomp5md.dll到同一个目录中由python setup.py build创建test.exe的了。在这之后,最小的test.exe显示了按下按钮时的matplotlib窗口。

这些文件位于文件夹lib \ site-packages \ numpy \ core

+0

这是惊人的家伙。我尝试了很多其他的东西,没有奏效。但即使对于我更复杂的GUI和绘图而言,它也可以工作。哇,非常感谢! – PuseMuckeL

+2

我正在使用Anaconda并且DLL不在lib/site-packages/numpy/code文件夹中。相反,我在Anaconda/Library/bin中找到了它们。 –

+0

在世界上你是如何知道如何使用libiomp5md.dll而不是其他的东西?你可以分享一下你的思考过程吗?如果我将来遇到类似的问题,它会帮助我。这个答案对我来说很神奇。我认真地认为它不会起作用。我的程序非常复杂。但你的解决方案只是简单的作品 – Frikster

相关问题