python-3.x - MatplotlibDeprecationWarning 与 Pyinstaller .exe

标签 python-3.x matplotlib pyinstaller

我遇到了一个警告,该警告仅在运行 pyinstaller 可执行文件时出现。

...appdata\local\programs\python\python37-32\lib\site-packages\PyInstaller\loader\pyimod03_importers.py:627: MatplotlibDeprecationWarning:
The MATPLOTLIBDATA environment variable was deprecated in Matplotlib 3.1 and will be removed in 3.3.
  exec(bytecode, module.__dict__)

我已经尝试了这里的所有建议:Python/matplotlib : getting rid of matplotlib.mpl warning

我也试过这个,最终结果没有任何变化:
Pyinstaller exe hide warning messages

最终可执行文件中出现的 MatplotlibDeprecation 警告没有任何更改。在 Pycharm 等 IDE 中运行代码时,基线不存在警告。

使用:
python 3.7.2
pyinstaller 3.5
Matplotlib 3.1.1

最佳答案

查找 here the pyinstaller issue这(部分)解决了这个问题。
已为 matplotlib >=3.1 引入了弃用警告。因此,环境变量 MATPLOTLIBDATA在 future 的版本中, Pandas 将不再使用。但是,由于我不太清楚的原因,PyInstaller 目前依赖于这个变量。
导致警告的代码段在 pyi_rth_mpldata.py 中找到:

os.environ["MATPLOTLIBDATA"] = os.path.join(sys._MEIPASS, "mpl-data")
不幸的是,简单地在本地取消注释该行 (site-packages/PyInstaller/loader/rthooks/rpyi_rth_mpldata.py) 不是一个选项,导致我的 PyInstaller 包崩溃。
我目前看到以下选项:
  • 降级 matplotlib 到 v3.0 ( pip install 'matplotlib==3.0.3' )
  • 本地禁用弃用警告 在 matplotlib ( matplotlib/__init__.py:625 )
  • 过滤警告 (参见 other answer 了解如何)
  • 等到补丁可用 ,或帮助 pyinstaller 工作人员找到一个...

  • 选项 1. 为我工作,希望你也很幸运。选项 2. 和 3. 是最简单的,应该没有任何副作用。

    关于python-3.x - MatplotlibDeprecationWarning 与 Pyinstaller .exe,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57517371/

    相关文章:

    python - 如何仅更改图例字体而不影响 matplotlib 中的其他参数?

    python-3.x - 模块未找到错误 : No module named 'Crypto.Math'

    python - 运行使用 folium 的可执行文件时,Branca Python 模块无法找到 2 个必要的 json 文件

    python - Python 百分位数函数

    python - 解析列表以获取精确值

    python - matplotlib多次打印标签的原因是什么?

    python - Matplotlib 在第一帧后停止动画

    python - 这个嵌套列表理解有什么问题?

    python - 如何找到python中有多少个单词?

    python - 使用 Pyinstaller 编译 PyQt4 时出错