I am failing to create a working exe file from my Python script. I was able to narrow it down to matplotlib usage, but I do not know how to fix.
I create exe file, using pyinstaller --onefile myScript.py
command. exe is created with some "ignored" imports such as:
INFO: Matplotlib backend "GTK3Agg": ignored backend Gtk3Agg requires cairo
When I run exe, a command window appears, gives an error and then terminates itself:
ERROR: Runtime error could not find the matplotlib data files
If I run the code from Python terminal, everything works fine. If I remove matplotlib and graph related lines, exe is created properly.
Some (pyinstaller and matplotlib - error while executring .exe) claims the solution is to update pyinstaller. I did, it did not help.
Some suggests not using plt
(Python Matplotlib runtime error upon closing the console), but then I couldn't make subplot
function work.
I feel this link (http://www.py2exe.org/index.cgi/MatPlotLib) is related but I do not understand what exactly I need to do. I got other errors when I try.
Here is my code:
import tkinter as tk
import tkinter.ttk as ttk
import matplotlib.pyplot as plt
class myApp(tk.Frame):
def __init__(self, parent, *args, **kwargs):
tk.Frame.__init__(self, parent, *args, **kwargs)
self.parent = parent
myFrame = ttk.LabelFrame(self.parent, text="FRAME", borderwidth=5)
myFrame.grid(row=0, column=2, padx=5, pady=5, sticky='NS')
myButton = ttk.Button(myFrame, width=12, text="SHOW GRAPH", command=self.showGraph) .grid(row=0, column=1, sticky=tk.S)
def showGraph(self):
fig, axs = plt.subplots(2, 3)
plt.show(block=False)
def main(root):
app = myApp(root)
root.wm_title("MyApp")
root.mainloop()
if __name__ == "__main__":
root = tk.Tk()
main(root)
else:
pass
Note: I am running Python 3.8.3, on Windows 10, pip version 20.2.2.