大家在使用Python的时候,肯定会接触到一些第三方的库,在我们安装的时候,会产生一下情况:
情况一:
会产生第三方库的版本和Python版本不兼容而引发的Warning或Error。如果是错误的话,则需要查看你的Python和第三方库的匹配版本。
情况二:
会产生第三方库和第三方库兼容性的冲突。如果是错误的话,则需要查看双方匹配的版本。
Warning解决办法
常见的Warning有:UserWarning、DeprecationWarning、RuntimeWarning、SyntaxWarning、FutureWarning、OverflowWarning、PendingDeprecationWarning等等,如果不想让控制台提示Warning信息可用一下方法解决
import warnings
warnings.filterwarnings("ignore")
分析一下:
def filterwarnings(action, message="", category=Warning, module="", lineno=0,
append=False):
"""Insert an entry into the list of warnings filters (at the front).
'action' -- one of "error", "ignore", "always", "default", "module",
or "once"
'message' -- a regex that the warning message must match
'category' -- a class that the warning must be a subclass of
'module' -- a regex that the module name must match
'lineno' -- an integer line number, 0 matches all warnings
'append' -- if true, append to the list of filters
"""
assert action in ("error", "ignore", "always", "default", "module",
"once"), "invalid action: %r" % (action,)
assert isinstance(message, str), "message must be a string"
assert isinstance(category, type), "category must be a class"
assert issubclass(category, Warning), "category must be a Warning subclass"
assert isinstance(module, str), "module must be a string"
assert isinstance(lineno, int) and lineno >= 0, \
"lineno must be an int >= 0"
if message or module:
import re
if message:
message = re.compile(message, re.I)
else:
message = None
if module:
module = re.compile(module)
else:
module = None
_add_filter(action, message, category, module, lineno, append=append)
可以发现,在函数使用中有如下参数:
“message”-警告消息必须匹配的正则表达式
“category”-警告必须是其子类的类
“module”-模块名称必须匹配的正则表达式
“lineno”一个整数行号,0与所有警告匹配
“append”如果为true,则追加到筛选器列表
显然,我们把action的状态改为“ignore”即可解决
希望对大家有帮助。