AttributeError: module 'warnings' has no attribute 'filterswarnings'

Viewed 1305

The code imports the 'warning' library at the beginning, The relevant code is as follows:

import warnings
warnings.filterswarnings('ignore')

when I run the code, it appears an error

AttributeError: module 'warnings' has no attribute 'filterswarnings'

later, I choose to pip install warnings to overcome this problem, then it appears

ERROR: Could not find a version that satisfies the requirement warnings (from versions: none)
ERROR: No matching distribution found for warnings 

now, I still have not overcome this problem. how can I do to overcome this problem?

1 Answers

That is simple. filterswarnings is invalid. As you can see in the docs, filterwarnings is the correct form. What you need is

warnings.filterwarnings('ignore')

Also pip install warnings is not going to work. Because warnings is a built-in library. You can't install built-in libraries using pip.

Related