Issue
I am trying to use matplotlib with Tkinter to create a stand-alone executable by pyinstall (command: pyinstaller --onefile main.py
).
The program works at the stations where the python installed. However, at the computers without any installed python the program crashes at the line, which calls pyplot (fig = plt.Figure()
). The crash occurs without any error.
I've tried upgrading/downgrading matplotlib or pyinstaller, changed Figure() to figure(), re-installed numpy, nothing helped, and I do not know what to do else. I ran it from command prompt and I haven't seen any messages.
UPD: I've tried --debug-imports
flag, and found the only line that differs between working and not working station is "exec(bytecode, module.dict)" that exists only in the debug-log of the working program. The line occurs after deprecation warning "D:\Prog_files\anaconda3\lib\site-packages\PyInstaller\loader\pyimod03_importers.py:493: MatplotlibDeprecationWarning:
The MATPLOTLIBDATA environment variable was deprecated in Matplotlib 3.1 and will be removed in 3.3."
Do you have any ideas on how I can fix it?
Code:
from tkinter import *
from tkinter import filedialog
import matplotlib
import matplotlib.pyplot as plt
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
def setplot(x, y):
fig = plt.Figure()
canvas = FigureCanvasTkAgg(fig, root)
canvas.get_tk_widget().pack(side=TOP, fill=BOTH, expand=1)
ax1 = fig.add_subplot(1, 1, 1)
(l, ) = ax1.plot(x, y)
def Quit():
global root
root.destroy()
def LoadFile():
xx = list(range(0,100))
yy = [i*i for i in xx]
setplot(xx, yy)
root = Tk()
root.geometry('700x500')
panelFrame = Frame(root, height = 60, bg = 'gray')
panelFrame.pack(side = 'top', fill = 'x')
loadBtn = Button(panelFrame, text = 'Plot', command = LoadFile)
quitBtn = Button(panelFrame, text = 'Exit', command = Quit)
loadBtn.pack()
loadBtn.place(x = 10, y = 10, width = 70, height = 40)
quitBtn.place(x = 100, y = 10, width = 70, height = 40)
root.mainloop()
Solution
I had a similar problem and after several searches I found a recipe that works. These are my configurations with Anaconda:
- python version 3.6
- pyinstaller version 3.6
- matplotlib version 3.0.3
Do not use pyinstaller with "--onefile" option so in the folder "dist" there will be various ".dll" files. And here is the problem, the file "libiomp5md.dll" is missing!
Then just copy to the folder "dist" the file "libiomp5md.dll" which is located in the Anaconda installation folder ...\Anaconda3\Library\bin
Answered By - Federico Valeri
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.