我一直在处理这个好几天了,希望能找到一些帮助。我开发了一个带有导入模块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。
知道这个问题是否与Windows 10相关,或者是否与其他Windows版本相同,将会很有趣。 –
啊,对不起,我忘了提及它。在Windows 7,64位机器上发生同样的WinPython分发问题。 – PuseMuckeL
刚刚在32位XP上试过这个没有问题,我会在64位win7以后尝试它 –