问题
运行python程序的时候老是跑出来一堆warnings,但是不影响程序正常运行。
警告消息如下所示:
C:\pythons\python3.6\lib\site-packages\win32\lib\pywintypes.py:3: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
import imp, sys, os
C:\pythons\python3.6\lib\site-packages\scipy\sparse\sparsetools.py:21: DeprecationWarning: `scipy.sparse.sparsetools` is deprecated!
scipy.sparse.sparsetools is a private module for scipy.sparse, and should not be used.
_deprecated()
不想看见这么多,于是想屏蔽。
但是试了如下方法都没用:
import warnings
warnings.filterwarnings('ignore')
import warnings
def fxn():
warnings.warn("deprecated", DeprecationWarning)
with warnings.catch_warnings():
warnings.simplefilter("ignore")
fxn()
解决方法
千搜万搜终于搜到了一个大神的方法:shutup的github源码
使用方法:
先安装 shutup
包:
pip install shutup
之后在代码最开头执行如下语句:
(要在import其他包之前执行!!!反正就写在最前面就完事!)
import shutup
shutup.please()
短短两行代码却有着惊天地泣鬼神的力量。
真的,我的世界寂静了。