【问题标题】:exe made by pyinstaller crashes at calling matplotlibpyinstaller 制作的 exe 在调用 matplotlib 时崩溃
【发布时间】: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


【解决方案1】:

我遇到了类似的问题,经过多次搜索,我找到了一个有效的食谱。这些是我对 Anaconda 的配置:

  • python 3.6版
  • pyinstaller 3.6 版
  • matplotlib 3.0.3 版

不要使用带有“--onefile”选项的pyinstaller,所以在文件夹“dist”中会有各种“.dll”文件。这就是问题所在,文件“libiomp5md.dll”丢失了!

然后只需将位于 Anaconda 安装文件夹 ...\Anaconda3\Library\bin 中的文件“libiomp5md.dll”复制到文件夹“dist”

【讨论】:

    【解决方案2】:

    我在一个使用过的项目中遇到了同样的问题

    • matplotlib
    • 熊猫
    • 枕头
    • pyinstaller
    • pysimplegui

    经过无数小时尝试一百万种不同的解决方案(DLL、cmd 行参数、--paths=""、钩子、阅读文档、尝试 cx freeze 和 py2exe 等)后,我通过简单地使用特定组合来随机修复它软件包版本...太令人沮丧了...

    • python 3.7.10
    • matplotlib 3.4.1
    • pyinstaller 4.3
    • pysimplegui 4.38

    我提到的其他软件包似乎没有什么不同。我真的希望它有帮助,我知道它有多痛苦。我建议从头开始创建一个新的 anaconda 环境并使用conda install -c conda-forge -n {envNameYouWant} pyinstaller=4.3 安装特定版本

    【讨论】:

      猜你喜欢
      • 2016-03-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-26
      • 1970-01-01
      相关资源
      最近更新 更多