Mehdi
Mehdi

Reputation: 1306

Hide warning message on import in python script

I want to import pydicom in python script. So, I use the following command to do so without having any warning message:

import sys, warnings
if not sys.warnoptions:
   warnings.simplefilter("ignore")
   try:
       import pydicom as dicom
   except ImportError:
       import dicom

But I get the following warning message yet!!!!

/Users/anaconda3/lib/python3.6/site-packages/dicom/__init__.py:53: UserWarning: 
This code is using an older version of pydicom, which is no longer 
maintained as of Jan 2017.  You can access the new pydicom features and API 
by installing `pydicom` from PyPI.
See 'Transitioning to pydicom 1.x' section at pydicom.readthedocs.org 
for more information.
warnings.warn(msg)
/Users/anaconda3/lib/python3.6/site-packages/h5py/__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
from ._conv import register_converters as _register_converters 

How can I hide it?

Upvotes: 1

Views: 1695

Answers (3)

Nick
Nick

Reputation: 339

from pydicom import config
config.settings.reading_validation_mode = config.IGNORE

Upvotes: 0

Nathan Villaescusa
Nathan Villaescusa

Reputation: 17649

This seems to work for me:

>>> import warnings
>>> try:
...     import pydicom as dicom
... except ImportError:
...     with warnings.catch_warnings():
...         warnings.simplefilter("ignore")
...         import dicom
... 
>>> 

Upvotes: 2

DJAG
DJAG

Reputation: 21

maybe -> python -W ignore archive.py

the option -W skips the warnings

Upvotes: 1

Related Questions