python - Pyinstaller 和 Matplotlib 的问题。文件 .exe 不起作用并且没有给出任何错误
问题描述
一般来说,我对 Python 和程序语言都很陌生。
我已经一个多星期没有在这方面取得任何进展,所以最后我试着在这里问(我的第一次!)。
和许多其他人一样(我到处搜索,但找不到任何可以帮助我的东西),我试图成功获得一个exe。使用 Pyinstaller从 Python 脚本(内部带有matplotlib模块)生成文件。
双击exe文件时当然会出现问题(使用anaconda或python编译器我没有任何问题)
我知道问题与matplolib及其相关行有关(如果我评论它们,exe 文件运行良好)
我尝试了很多东西,比如降级 matplotlib、pyinstaller、使用不同的计算机和版本的 python、使用不同的类型来绘制,但这些都不起作用。
以下是一个不起作用的脚本的简单示例 `
import matplotlib
from matplotlib.figure import Figure
import numpy as np
t = np.arange(0.0, 2.0, 0.01)
s = 1 + np.sin(2 * np.pi * t)
fig= Figure()
ax = fig.add_subplot(111)
ax.plot(t, s)
ax.set(xlabel='time (s)', ylabel='voltage (mV)',
title='About as simple as it gets, folks')
ax.grid()
fig.savefig("test.png")`enter code here`
我检测到问题从前一个案例“ fig= Figure() ”中的第一个 matplotlib 命令开始,但其他时候是“ fig, ax = plt.subplots() ”或“plt.show() ”(当然有将 matplotli.pyplot 导入为 plt)"
另一个问题是,当在一段时间后双击 .exe 时,窗口关闭而没有任何明确的错误消息。
使用--debug=all崩溃前的最后一行运行 pyinstaller如下在此处输入图像描述
所以它停在import matplotlib.pyplot(在附加的脚本中,因为它停在import matplotlib.figure)。我还通过--hidden-import=matplotlib.pyplot将这些导入添加到隐藏导入,但没有任何改变。
有人有一些建议吗?请帮我解决这个问题:)
pyinstaller 版本 4.2 python 3.8.5 / 3.7 / 3.9.4 matplotlib 3.1.3(从 3.4.1 降级)
赢10
非常感谢您的建议,
斯特凡诺
编辑
极好的!最后,我通过安装没有任何 --add.data, hidden file ext 的 DEV 版本的 pyinstaller 成功解决了这个问题:
pip install github.com/pyinstaller/pyinstaller/archive/develop.zip
解决方案
推荐阅读
- c# - 如何在非活动类中使用 Xamarin.Firebase.Auth 并获得通知?
- java - Java 10 JavaFX java.lang.IllegalAccessError
- html - 将页脚保持在底部,但不固定
- mysql - 如何从查询中选择最后一个值?
- javascript - 如何仅在 Swiper JS 中为中间幻灯片启用中心幻灯片?
- python - AttributeError:“NoneType”对象没有“形状”属性/从多个轮廓框转换为单数
- python - 使用 Pandas 提取包含特定字符的数据
- unix - 格罗夫图像在同一行?
- ckeditor - CKEditor 5 更改事件并不总是触发
- mysql - SQL UPDATE boolean 从 db 中选择数字的最小值 WHERE boolean=false