Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MatplotlibDeprecationWarning with Pyinstaller .exe

I have run into a warning that only appears when the pyinstaller executable is run.

...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__)

I have tried all of the suggestions here: Python/matplotlib : getting rid of matplotlib.mpl warning

I have also tried this without any change in the end result: Pyinstaller exe hide warning messages

without any change in the MatplotlibDeprecation warnings appearing in the final executable. The warnings are baseline not present when running the code in an IDE such as Pycharm.

Using: Python 3.7.2 Pyinstaller 3.5 Matplotlib 3.1.1

like image 420
blackbird Avatar asked Aug 15 '19 23:08

blackbird


1 Answers

Find here the pyinstaller issue that (partly) addresses this problem.

The deprecation warning has been introduced for matplotlib >=3.1. Accordingly, the environment variable MATPLOTLIBDATA will not be used anymore by pandas in future versions. However, PyInstaller currently relies on this variable for reasons not entirely clear to me.

The piece of code causing the warning is found in pyi_rth_mpldata.py:

os.environ["MATPLOTLIBDATA"] = os.path.join(sys._MEIPASS, "mpl-data")

Unfortunately, simply uncommenting the line locally (site-packages/PyInstaller/loader/rthooks/rpyi_rth_mpldata.py) is not an option, causing my PyInstaller bundles to crash.

I see currently the following options:

  1. downgrade matplotlib to v3.0 (pip install 'matplotlib==3.0.3')
  2. locally disable the deprecation warning in matplotlib (matplotlib/__init__.py:625)
  3. Filter warnings (see the other answer for how)
  4. wait until a patch is available, or help the pyinstaller crew in finding one...

Option 1. was working for me, hopefully you are lucky as well. Options 2. and 3. are the easiest and should not have any side effects.

like image 74
normanius Avatar answered Sep 27 '22 21:09

normanius