如何抑制pyinstaller生成的可执行文件窗口中的所有警告 [英] How to suppress all warnings in window of executable file generated by pyinstaller
问题描述
我已经使用pyinstaller从python文件生成了可执行文件.该程序可以正常工作,但是在我要隐藏的窗口中显示了此警告消息.
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.
当在IDE中运行python文件时,以下行不会显示所有警告消息.
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__)
推荐答案
如果要使用自定义的 spec
构建文件,则只需将以下行添加到 spec 代码>文件以禁止这些启动警告(根据
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')],
# ...
因为 spec
文件实际上是一个 python 脚本,你可以用 os.getcwd()
替换 pathex
并确保你已经已经在 spec
文件中导入 os
模块.
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.
我在Windows 10 和 Python 3.7.4
和 pyinstaller 3.5
上进行了尝试.可行!
I've tried on Windows 10
with Python 3.7.4
and pyinstaller 3.5
. It works!
由于您提供了自定义的 spec
文件,因此基本的构建命令应更改为:
Since you've provided a customized spec
file, your basic building command should change to:
pyinstaller xxx.spec
请告诉我它是否有效.
这篇关于如何抑制pyinstaller生成的可执行文件窗口中的所有警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!