pyinstaller 制作的 exe 在调用 matplotlib 时崩溃
exe made by pyinstaller crashes at calling matplotlib
我正在尝试将 matplotlib 与 Tkinter 结合使用,通过 pyinstall(命令:pyinstaller --onefile main.py
)创建一个独立的可执行文件。
该程序在安装了 python 的站点上运行。然而,在没有安装任何 python 的计算机上,程序在调用 pyplot (fig = plt.Figure()
) 的行崩溃。崩溃发生,没有任何错误。
我试过 upgrading/downgrading 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()
我遇到了类似的问题,经过多次搜索,我找到了一个有效的食谱。这些是我对 Anaconda 的配置:
- python 版本 3.6
- pyinstaller 版本 3.6
- matplotlib 版本 3.0.3
不要使用带“--onefile”选项的pyinstaller,这样在“dist”文件夹中会有各种“.dll”文件。问题来了,文件“libiomp5md.dll”丢失了!
然后只需将位于 Anaconda 安装文件夹中的文件“libiomp5md.dll”复制到文件夹“dist”...\Anaconda3\Library\bin
我在使用
的项目中遇到了完全相同的问题
- matplotlib
- pandas
- 枕头
- 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
安装特定版本
我正在尝试将 matplotlib 与 Tkinter 结合使用,通过 pyinstall(命令:pyinstaller --onefile main.py
)创建一个独立的可执行文件。
该程序在安装了 python 的站点上运行。然而,在没有安装任何 python 的计算机上,程序在调用 pyplot (fig = plt.Figure()
) 的行崩溃。崩溃发生,没有任何错误。
我试过 upgrading/downgrading 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()
我遇到了类似的问题,经过多次搜索,我找到了一个有效的食谱。这些是我对 Anaconda 的配置:
- python 版本 3.6
- pyinstaller 版本 3.6
- matplotlib 版本 3.0.3
不要使用带“--onefile”选项的pyinstaller,这样在“dist”文件夹中会有各种“.dll”文件。问题来了,文件“libiomp5md.dll”丢失了!
然后只需将位于 Anaconda 安装文件夹中的文件“libiomp5md.dll”复制到文件夹“dist”...\Anaconda3\Library\bin
我在使用
的项目中遇到了完全相同的问题- matplotlib
- pandas
- 枕头
- 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