Reputation: 3
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()
Upvotes: 0
Views: 1229
Reputation: 199
I had the same exact issue in a project that used
After endless hours trying a million different solutions (DLLs, cmd line parameters, --paths="", hooks, reading the docs, trying cx freeze and py2exe instead etc.) i fixed it randomly by simply using a specific combination of package versions... so frustrating...
The rest of the packages that I mentioned don't seem to have made a difference. I really hope it helps, i know how painful it is. I suggest creating a new anaconda environment from scratch and installing the specific versions with conda install -c conda-forge -n {envNameYouWant} pyinstaller=4.3
Upvotes: 2
Reputation: 36
I had a similar problem and after several searches I found a recipe that works. These are my configurations with Anaconda:
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
Upvotes: 2