diff --git a/javaobj/v1/unmarshaller.py b/javaobj/v1/unmarshaller.py index 4895a26..3d0efb8 100644 --- a/javaobj/v1/unmarshaller.py +++ b/javaobj/v1/unmarshaller.py @@ -65,11 +65,7 @@ hexdump, ) -# Numpy array support -try: - import numpy -except ImportError: - numpy = None +numpy = None # Imported only when really used # ------------------------------------------------------------------------------ @@ -113,6 +109,15 @@ def __init__(self, stream, use_numpy_arrays=False): """ self.use_numpy_arrays = use_numpy_arrays + # Numpy array support + if self.use_numpy_arrays: + try: + global numpy + import numpy as np + numpy = np + except ImportError: + pass + # Check stream if stream is None: raise IOError("No input stream given")