[BUG] *monai* and *monai-deploy-app-sdk* could not co-exist
george-kuanli-peng opened this issue · 1 comments
Describe the bug
monai
could not be imported when pip packages for monai and monai-deploy-app-sdk are both installed.
Steps/Code to reproduce bug
- Create a new conda/virtual environment.
pip install monai-deploy-app-sdk
python -c "import monai"
pip install monai
python -c "import monai"
Expected behavior
Importing monai
works in both steps 3 and 5.
Actual behavior
Importing monai
works in step 3, but fails in step 5 with the following error:
Traceback (most recent call last): [12/1061] File "/opt/conda/lib/python3.8/site-packages/monai/utils/module.py", line 199, in load_submodules
mod = import_module(name)
File "/opt/conda/lib/python3.8/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "/opt/conda/lib/python3.8/site-packages/monai/deploy/operators/__init__.py", line 38, in <module>
from .dicom_seg_writer_operator import DICOMSegmentationWriterOperator
File "/opt/conda/lib/python3.8/site-packages/monai/deploy/operators/dicom_seg_writer_operator.py", line 44, in <module>
class SegmentDescription:
File "/opt/conda/lib/python3.8/site-packages/monai/deploy/operators/dicom_seg_writer_operator.py", line 53, in SegmentDescription
algorithm_family: Code = codes.DCM.ArtificialIntelligence,
File "/opt/conda/lib/python3.8/site-packages/monai/deploy/utils/importutil.py", line 262, in __getattr__
raise self._exception
File "/opt/conda/lib/python3.8/site-packages/monai/deploy/utils/importutil.py", line 221, in optional_import
pkg = __import__(module) # top level module
monai.deploy.utils.importutil.OptionalImportError: from pydicom.sr.codedict import codes (No module named 'pydicom').
For details about installing the optional dependencies, please visit:
https://docs.monai.io/en/latest/installation.html#installing-the-recommended-dependencies
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/opt/conda/lib/python3.8/site-packages/monai/__init__.py", line 55, in <module>
load_submodules(sys.modules[__name__], False, exclude_pattern=excludes)
File "/opt/conda/lib/python3.8/site-packages/monai/utils/module.py", line 209, in load_submodules
raise type(e)(f"{e}\n{msg}").with_traceback(e.__traceback__) from e # raise with modified message
File "/opt/conda/lib/python3.8/site-packages/monai/utils/module.py", line 199, in load_submodules
mod = import_module(name)
File "/opt/conda/lib/python3.8/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "/opt/conda/lib/python3.8/site-packages/monai/deploy/operators/__init__.py", line 38, in <module>
from .dicom_seg_writer_operator import DICOMSegmentationWriterOperator
File "/opt/conda/lib/python3.8/site-packages/monai/deploy/operators/dicom_seg_writer_operator.py", line 44, in <module>
class SegmentDescription:
File "/opt/conda/lib/python3.8/site-packages/monai/deploy/operators/dicom_seg_writer_operator.py", line 53, in SegmentDescription
algorithm_family: Code = codes.DCM.ArtificialIntelligence,
File "/opt/conda/lib/python3.8/site-packages/monai/deploy/utils/importutil.py", line 262, in __getattr__
raise self._exception
File "/opt/conda/lib/python3.8/site-packages/monai/deploy/utils/importutil.py", line 221, in optional_import
pkg = __import__(module) # top level module
monai.deploy.utils.importutil.OptionalImportError: from pydicom.sr.codedict import codes (No module named 'pydicom').
For details about installing the optional dependencies, please visit:
https://docs.monai.io/en/latest/installation.html#installing-the-recommended-dependencies
Multiple versions of MONAI may have been installed?
Please see the installation guide: https://docs.monai.io/en/stable/installation.html
Environment details (please complete the following information)
- OS/Platform: Ubuntu
- Python Version: Python 3.8, Python 3.11
- Method of MONAI Deploy App SDK install: [pip, conda, Docker, or from source] pip (in conda)
- SDK Version:
- monai 1.1.0
- monai-deploy-app-sdk 0.5.0
@george-kuanli-peng Thanks for reporting this issue, which can be reproduced.
The root cause is not that monai (core) and monai deploy app sdk could not co-exist, despite the fact the deploy app sdk shares the same package folder path with monai (core) itself.
The root cause is one of the "optional imports" in the dicom_seg_writer_operator module which contains the class DICOMSegmentationWriterOperator. This class depends on highdicom package which in turn depends on pydicom. Typically the optional imports as implemented in monai (core) and app sdk do work, but in this case, due to the use of one of attributes in the optionally imported pydicom package, both pydicom and highdicom must be pip installed and present. This by itself does not present as an issue and in fact required by most of the applications built with the monai deploy app sdk, for pydicom and highdicom are needed for parsing DICOM inputs and saving segmentation image in DICOM SEG OID.
So, please install the two dependencies before install monai and monai deploy app sdk,
pip install pydicom
pip install highdicom