title: Matplotlib Usage in Standalone (Exe) Python File
body: <p>I am failing to create a working <em>exe</em> file from my Python script. I was able to narrow it down to matplotlib usage, but I do not know how to fix.</p>
  <p>I create <em>exe</em> file, using <code>pyinstaller --onefile myScript.py</code> command. <em>exe</em> is created with some &quot;ignored&quot; imports such as:</p>
  <blockquote>
  <p>INFO:   Matplotlib backend &quot;GTK3Agg&quot;: ignored
  backend Gtk3Agg requires cairo</p>
  </blockquote>
  <p>When I run <em>exe</em>, a command window appears, gives an error and then terminates itself:</p>
  <blockquote>
  <p>ERROR: Runtime error could not find the matplotlib data files</p>
  </blockquote>
  <p>If I run the code from Python terminal, everything works fine.
  If I remove matplotlib and graph related lines, <em>exe</em> is created properly.</p>
  <p>Some (<a href="https://stackoverflow.com/questions/39038899/pyinstaller-and-matplotlib-error-while-executring-exe">pyinstaller and matplotlib - error while executring .exe</a>) claims the solution is to update pyinstaller. I did, it did not help.</p>
  <p>Some suggests not using <code>plt</code> (<a href="https://stackoverflow.com/questions/17252566/python-matplotlib-runtime-error-upon-closing-the-console">Python Matplotlib runtime error upon closing the console</a>), but then I couldn't make <code>subplot</code> function work.</p>
  <p>I feel this link (<a href="http://www.py2exe.org/index.cgi/MatPlotLib" rel="nofollow noreferrer">http://www.py2exe.org/index.cgi/MatPlotLib</a>) is related but I do not understand what exactly I need to do. I got other errors when I try.</p>
  <p>Here is my code:</p>
  <pre><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=&quot;FRAME&quot;, borderwidth=5)
          myFrame.grid(row=0, column=2, padx=5, pady=5, sticky='NS')
          myButton = ttk.Button(myFrame, width=12, text=&quot;SHOW GRAPH&quot;, 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(&quot;MyApp&quot;)
      root.mainloop()
  
  if __name__ == &quot;__main__&quot;:
      root = tk.Tk()
      main(root)
  else:
      pass 
  </code></pre>
  <p>Note: I am running Python 3.8.3, on Windows 10, pip version 20.2.2.</p>