pyinstaller生成的exe在调用matplotlib时崩溃

2024-09-27 23:19:28 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试将matplotlib与Tkinter结合使用,通过pyinstall创建一个独立的可执行文件(命令:pyinstaller --onefile main.py)。 该程序在安装python的工作站上运行。但是,在没有安装任何python的计算机上,程序在调用pyplot(fig = plt.Figure())的第行崩溃。崩溃发生时没有任何错误

我尝试升级/降级matplotlib或pyinstaller,将Figure()更改为Figure(),重新安装numpy,但没有任何帮助,我不知道还能做什么。我在命令提示符下运行了它,但没有看到任何消息

UPD:我尝试了--debug-imports标志,发现工作站和非工作站之间唯一不同的行是“exec(字节码,module.dict)”,它只存在于工作程序的调试日志中。该行出现在弃用警告“D:\Prog\u files\anaconda3\lib\site packages\PyInstaller\loader\pyimod03\u importers”之后。py:493:MatplotlibDeprecationWarning: Matplotlib环境变量在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()

Tags: fromimport程序matplotlibdeffigpltroot
2条回答

我有一个类似的问题,经过几次搜索,我发现了一个有效的配方。以下是我对Anaconda的配置:

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

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

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

我在一个使用

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

在无数个小时尝试了一百万种不同的解决方案(DLL、cmd行参数、path=”“、hooks、读取文档、尝试cx freeze和py2exe等)之后,我通过使用特定的软件包版本组合随机修复了它如此令人沮丧……

  • python 3.7.10
  • matplotlib 3.4.1
  • pyinstaller 4.3
  • pysimplegui4.38

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

相关问题 更多 >

    热门问题