How to suppress all warnings in window of executable file generated by pyinstaller

六月ゝ 毕业季﹏ 提交于 2020-01-23 12:22:25

问题


I have generated an executable file from a python file using pyinstaller. The program works how it is supposed to work but there is this warning message it appears in the window that I would like to hide.

The following line does suppress all warning messages when the python file is run within the IDE.

warnings.filterwarnings('ignore')

But in the window of the executable file, this warning is displayed:

\venv\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__)

回答1:


If you are going to using a customized spec building file, you can just add following line to your spec files to suppress these startup warnings(according to https://pyinstaller.readthedocs.io/en/stable/spec-files.html#giving-run-time-python-options):

exe = EXE(pyz,
      a.scripts,
      [('W ignore', None, 'OPTION')],
      # ...

Since a spec file is actually a python script, you can replace pathex with os.getcwd() and make sure you've already import os module in your spec file.

I've tried on Windows 10 with Python 3.7.4 and pyinstaller 3.5. It works!


Since you've provided a customized spec file, your basic building command should change to:

pyinstaller xxx.spec

Please let me know if it works.



来源:https://stackoverflow.com/questions/56701417/how-to-suppress-all-warnings-in-window-of-executable-file-generated-by-pyinstall

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!