【发布时间】:2021-02-19 14:40:34
【问题描述】:
我正在尝试使用 matplotlib 和 Tkinter 通过 pyinstall(命令:pyinstaller --onefile main.py)创建一个独立的可执行文件。
该程序在安装了 python 的站点上运行。但是,在没有安装任何 python 的计算机上,程序在调用 pyplot (fig = plt.Figure()) 的行处崩溃。崩溃发生时没有任何错误。
我尝试升级/降级 matplotlib 或 pyinstaller,将 Figure() 更改为 figure(),重新安装了 numpy,没有任何帮助,我不知道还能做什么。我从命令提示符运行它,但没有看到任何消息。
UPD:我试过--debug-imports 标志,发现工作站和非工作站之间唯一不同的行是“exec(bytecode, module.dict)”,它只存在于工作程序的调试日志。该行出现在弃用警告“D:\Prog_files\anaconda3\lib\site-packages\PyInstaller\loader\pyimod03_importers.py:493: MatplotlibDeprecationWarning:
MATPLOTLIBDATA 环境变量在 Matplotlib 3.1 中已弃用,将在 3.3 中删除。"
您对我如何解决它有任何想法吗?
代码:
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()
【问题讨论】:
-
您是否尝试过描述的各种方法来帮助了解当您的应用无法启动时会发生什么pyinstaller.readthedocs.io/en/stable/…
-
特别是,从命令提示符启动您的 exe 并编辑您进入问题的完整错误消息。
-
您是否 100% 确定程序会静默崩溃,即没有向控制台窗口写入任何内容,或者没有显示包含错误消息的消息框?
-
@pts,在调用 matplotlib 后,调试所有机制中的唯一消息是“加载器:返回父级 (RC = -1066598274)”。没有 debug-all 命令提示符会静默结束程序 :(.
-
@giosans,不幸的是没有。最终,我使用 Tkinter 画布工具绘制绘图,效果很好。
标签: python matplotlib tkinter pyinstaller