How to ignore deprecation warnings in Python


I keep getting this :

DeprecationWarning: integer argument expected, got float

How do I make this message go away? Is there a way to avoid warnings in Python?

2/7/2012 1:09:34 PM

Accepted Answer

From documentation of the warnings module:

 #!/usr/bin/env python -W ignore::DeprecationWarning

If you're on Windows: pass -W ignore::DeprecationWarning as an argument to Python. Better though to resolve the issue, by casting to int.

(Note that in Python 3.2, deprecation warnings are ignored by default.)

9/28/2017 7:00:50 AM

I had these:

DeprecationWarning: the md5 module is deprecated; use hashlib instead import os, md5, sys

DeprecationWarning: the sha module is deprecated; use the hashlib module instead import sha

Fixed it with:

import warnings

with warnings.catch_warnings():
    import md5, sha


Now you still get all the other DeprecationWarnings, but not the ones caused by:

import md5, sha

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow