Skip to content

Commit bb9cb15

Browse files
committed
RF: minc - delay import of h5py until needed.
On Debian systems h5py comes with MPI enabled build. I guess on some misconfigured systems, like my laptop, it might take awhile to import. And since h5py here is imported upon import of `nibabel`, it makes it long(er) to import it. Here is timing on my laptop before the change: $> time python -c 'import nibabel' python -c 'import nibabel' 0.20s user 0.08s system 5% cpu 5.356 total and here is after the change: $> time python -c 'import nibabel' python -c 'import nibabel' 0.13s user 0.02s system 100% cpu 0.150 total
1 parent bcce691 commit bb9cb15

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

nibabel/minc2.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727
"""
2828
import numpy as np
2929

30-
from ._h5py_compat import h5py
31-
3230
from .minc1 import Minc1File, MincHeader, Minc1Image, MincError
3331

3432

@@ -158,6 +156,9 @@ class Minc2Image(Minc1Image):
158156

159157
@classmethod
160158
def from_file_map(klass, file_map, *, mmap=True, keep_file_open=None):
159+
# Import of h5py might take awhile for MPI-enabled builds
160+
# So we are importing it here "on demand"
161+
from ._h5py_compat import h5py
161162
holder = file_map['image']
162163
if holder.filename is None:
163164
raise MincError('MINC2 needs filename for load')

0 commit comments

Comments
 (0)