Skip to content

Commit 9943299

Browse files
authored
Quick fix to avoid package not found error by use optional import (#386)
* Use optional import Signed-off-by: M Q <[email protected]> * Also add env packages Signed-off-by: M Q <[email protected]> Signed-off-by: M Q <[email protected]>
1 parent 5698e4c commit 9943299

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

monai/deploy/operators/nii_data_loader_operator.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,17 @@
1010
# limitations under the License.
1111

1212
import numpy as np
13-
import SimpleITK
1413

1514
import monai.deploy.core as md
1615
from monai.deploy.core import DataPath, ExecutionContext, InputContext, IOType, Operator, OutputContext
16+
from monai.deploy.utils.importutil import optional_import
17+
18+
SimpleITK, _ = optional_import("SimpleITK")
1719

1820

1921
@md.input("image_path", DataPath, IOType.DISK)
2022
@md.output("image", np.ndarray, IOType.IN_MEMORY)
23+
@md.env(pip_packages=["SimpleITK>=2.0.2"])
2124
class NiftiDataLoader(Operator):
2225
"""
2326
This operator reads a nifti image, extracts the numpy array and forwards it to the next operator
@@ -42,7 +45,7 @@ def convert_and_save(self, nii_path):
4245
def test():
4346
filepath = "/home/gupta/Documents/mni_icbm152_nlin_sym_09a/mni_icbm152_gm_tal_nlin_sym_09a.nii"
4447
nii_operator = NiftiDataLoader()
45-
image_np = nii_operator.convert_and_save(filepath)
48+
_ = nii_operator.convert_and_save(filepath)
4649

4750

4851
def main():

0 commit comments

Comments
 (0)