【问题标题】:How to suppress all warnings in window of executable file generated by pyinstaller如何抑制pyinstaller生成的可执行文件窗口中的所有警告
【发布时间】:2019-11-04 04:27:15
【问题描述】:

我使用 pyinstaller 从 python 文件生成了一个可执行文件。该程序按应有的方式运行,但在我想隐藏的窗口中显示了此警告消息。

当 python 文件在 IDE 中运行时,以下行会抑制所有警告消息。

warnings.filterwarnings('ignore')

但是在可执行文件的窗口中,却显示了这个警告:

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

【问题讨论】:

    标签: python matplotlib pyinstaller


    【解决方案1】:

    如果你打算使用自定义的spec 构建文件,你可以在你的spec 文件中添加以下行来抑制这些启动警告(根据https://pyinstaller.readthedocs.io/en/stable/spec-files.html#giving-run-time-python-options):

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

    由于spec 文件实际上是一个python 脚本,您可以将pathex 替换为os.getcwd() 并确保您已经在os 文件中导入了os 模块。

    我已经在Windows 10Python 3.7.4pyinstaller 3.5 上进行了尝试。有效!


    由于您提供了自定义的spec 文件,您的基本构建命令应更改为:

    pyinstaller xxx.spec
    

    如果有效,请告诉我。

    【讨论】:

    • 是的,它有效!非常感谢。抱歉,我之前无法检查。
    • 有什么方法可以在现有的构建中做到这一点,而无需再次构建?
    • @Eren 恐怕你不能。由于它已经是一个可执行的二进制文件,并且该选项应该会影响构建它的方式。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-11
    • 2011-10-18
    • 2011-02-11
    • 2011-01-04
    相关资源
    最近更新 更多