简体   繁体   English

无法使用 warnings.filterwarnings("ignore") 抑制 Python 警告

[英]Cannot supress Python Warnings with warnings.filterwarnings("ignore")

I am using the following to suppress my warnings.我正在使用以下内容来抑制我的警告。 Sometimes the warning are suppressed, while more recently they are of no use and the warnings still appear.有时警告被抑制,而最近它们没有用并且警告仍然出现。

> import warnings  
> warnings.filterwarnings("ignore")

I am using Jupyter-notebook and working with Tensorflow (also with Keras, but not for this particular question, but the same thing happens with Keras as well)我正在使用 Jupyter-notebook 并使用 Tensorflow(也使用 Keras,但不是针对这个特定问题,但 Keras 也会发生同样的事情)

If it stopped working maybe you forgot to execute first the cell with the ignoring code?如果它停止工作,也许您忘记首先执行带有忽略代码的单元格?

import warnings
warnings.filterwarnings('ignore')
warnings.simplefilter('ignore')

Please note the additional line as per the answer to Disable warnings in jupyter notebook .请注意在 jupyter notebook 中禁用警告的答案中的附加行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM