axondeepseg / napari-plugin

A (work in progress) plugin for napari that implements the AxonDeepSeg tools
0 stars 0 forks source link

Failed to import command #4

Closed jcohenadad closed 1 year ago

jcohenadad commented 1 year ago

After a fresh installation of napari following https://github.com/axondeepseg/napari-plugin#instructions-to-install-the-plugin, I launch napari and click on the ADS plugin, and observe the following error

Screen Shot 2023-02-17 at 11 48 40 AM

Terminal output ```console --------------------------------------------------------------------------- ModuleNotFoundError Traceback (most recent call last) File ~/miniconda3/envs/ads_venv_napari/lib/python3.8/site-packages/npe2/_command_registry.py:33, in CommandHandler.resolve(self=CommandHandler(id='napari-ADS.make_qwidget', fun...None, python_name='napari_ADS._widget:ADSplugin')) 32 try: ---> 33 self.function = utils.import_python_name(self.python_name) self.function = None self.python_name = 'napari_ADS._widget:ADSplugin' self = CommandHandler(id='napari-ADS.make_qwidget', function=None, python_name='napari_ADS._widget:ADSplugin') utils = 34 except Exception as e: File ~/miniconda3/envs/ads_venv_napari/lib/python3.8/site-packages/npe2/manifest/utils.py:255, in import_python_name(python_name='napari_ADS._widget:ADSplugin') 253 module_name, funcname = match.groups() # type: ignore [union-attr] --> 255 mod = import_module(module_name) module_name = 'napari_ADS._widget' 256 return getattr(mod, funcname) File ~/miniconda3/envs/ads_venv_napari/lib/python3.8/importlib/__init__.py:127, in import_module(name='napari_ADS._widget', package=None) 126 level += 1 --> 127 return _bootstrap._gcd_import(name[level:], package, level) level = 0 name = 'napari_ADS._widget' name[level:] = 'napari_ADS._widget' package = None _bootstrap = File :1014, in _gcd_import(name='napari_ADS._widget', package=None, level=0) File :991, in _find_and_load(name='napari_ADS._widget', import_=) File :961, in _find_and_load_unlocked(name='napari_ADS._widget', import_=) File :219, in _call_with_frames_removed(f=, *args=('napari_ADS',), **kwds={}) File :1014, in _gcd_import(name='napari_ADS', package=None, level=0) File :991, in _find_and_load(name='napari_ADS', import_=) File :975, in _find_and_load_unlocked(name='napari_ADS', import_=) File :671, in _load_unlocked(spec=ModuleSpec(name='napari_ADS', loader=<_frozen_im...ulien/code/napari-plugin/napari-ADS/napari_ADS'])) File :843, in exec_module(self=<_frozen_importlib_external.SourceFileLoader object>, module=) File :219, in _call_with_frames_removed(f=, *args=( at 0x7fd7b29712f0, file "/...lugin/napari-ADS/napari_ADS/__init__.py", line 1>, {'__builtins__': {'ArithmeticError': , 'AssertionError': , 'AttributeError': , 'BaseException': , 'BlockingIOError': , 'BrokenPipeError': , 'BufferError': , 'BytesWarning': , 'ChildProcessError': , 'ConnectionAbortedError': , ...}, '__cached__': '/Users/julien/code/napari-plugin/napari-ADS/napari_ADS/__pycache__/__init__.cpython-38.pyc', '__doc__': None, '__file__': '/Users/julien/code/napari-plugin/napari-ADS/napari_ADS/__init__.py', '__loader__': <_frozen_importlib_external.SourceFileLoader object>, '__name__': 'napari_ADS', '__package__': 'napari_ADS', '__path__': ['/Users/julien/code/napari-plugin/napari-ADS/napari_ADS'], '__spec__': ModuleSpec(name='napari_ADS', loader=<_frozen_im...ulien/code/napari-plugin/napari-ADS/napari_ADS']), '__version__': '0.0.1'}), **kwds={}) File ~/code/napari-plugin/napari-ADS/napari_ADS/__init__.py:3 1 __version__ = "0.0.1" ----> 3 from ._widget import ADSplugin 5 __all__ = ( 6 "ADSplugin" 7 ) File ~/code/napari-plugin/napari-ADS/napari_ADS/_widget.py:6 4 from pathlib import Path ----> 6 import config 7 import numpy as np ModuleNotFoundError: No module named 'config' The above exception was the direct cause of the following exception: RuntimeError Traceback (most recent call last) File ~/miniconda3/envs/ads_venv_napari/lib/python3.8/site-packages/napari/_qt/menus/plugins_menu.py:99, in PluginsMenu._add_plugin_actions.._add_toggle_widget(key=('napari-ADS', 'ADS plugin'), hook_type='dock') 96 return 98 if hook_type == 'dock': ---> 99 self._win.add_plugin_dock_widget(*key) key = ('napari-ADS', 'ADS plugin') self._win = self = 100 else: 101 self._win._add_plugin_function_widget(*key) File ~/miniconda3/envs/ads_venv_napari/lib/python3.8/site-packages/napari/_qt/qt_main_window.py:696, in Window.add_plugin_dock_widget(self=, plugin_name='napari-ADS', widget_name='ADS plugin', tabify=False) 693 Widget = None 694 dock_kwargs = {} --> 696 if result := _npe2.get_widget_contribution(plugin_name, widget_name): widget_name = 'ADS plugin' plugin_name = 'napari-ADS' _npe2 = 697 Widget, widget_name = result 699 if Widget is None: File ~/miniconda3/envs/ads_venv_napari/lib/python3.8/site-packages/napari/plugins/_npe2.py:125, in get_widget_contribution(plugin_name='napari-ADS', widget_name='ADS plugin') 123 if contrib.plugin_name == plugin_name: 124 if not widget_name or contrib.display_name == widget_name: --> 125 return contrib.get_callable(), contrib.display_name contrib = WidgetContribution(command='napari-ADS.make_qwidget', display_name='ADS plugin', autogenerate=False) contrib.display_name = 'ADS plugin' 126 widgets_seen.add(contrib.display_name) 127 if widget_name and widgets_seen: File ~/miniconda3/envs/ads_venv_napari/lib/python3.8/site-packages/npe2/manifest/contributions/_widgets.py:50, in WidgetContribution.get_callable(self=WidgetContribution(command='napari-ADS.make_qwidget', display_name='ADS plugin', autogenerate=False), _registry=None) 47 def get_callable( 48 self, _registry: Optional[CommandRegistry] = None 49 ) -> Callable[..., Widget]: ---> 50 func = super().get_callable() 51 if self.autogenerate: 52 try: File ~/miniconda3/envs/ads_venv_napari/lib/python3.8/site-packages/npe2/manifest/utils.py:72, in Executable.get_callable(self=WidgetContribution(command='napari-ADS.make_qwidget', display_name='ADS plugin', autogenerate=False), _registry=) 69 from .._plugin_manager import PluginManager 71 _registry = PluginManager.instance().commands ---> 72 return _registry.get(self.command) _registry = self.command = 'napari-ADS.make_qwidget' self = WidgetContribution(command='napari-ADS.make_qwidget', display_name='ADS plugin', autogenerate=False) File ~/miniconda3/envs/ads_venv_napari/lib/python3.8/site-packages/npe2/_command_registry.py:132, in CommandRegistry.get(self=, id='napari-ADS.make_qwidget') 130 if id not in self._commands: # sourcery skip 131 raise KeyError(f"command {id!r} not registered") --> 132 return self._commands[id].resolve() id = 'napari-ADS.make_qwidget' self._commands = {'napari-ADS.make_qwidget': CommandHandler(id='napari-ADS.make_qwidget', function=None, python_name='napari_ADS._widget:ADSplugin')} self = self._commands[id] = CommandHandler(id='napari-ADS.make_qwidget', function=None, python_name='napari_ADS._widget:ADSplugin') File ~/miniconda3/envs/ads_venv_napari/lib/python3.8/site-packages/npe2/_command_registry.py:35, in CommandHandler.resolve(self=CommandHandler(id='napari-ADS.make_qwidget', fun...None, python_name='napari_ADS._widget:ADSplugin')) 33 self.function = utils.import_python_name(self.python_name) 34 except Exception as e: ---> 35 raise RuntimeError( 36 f"Failed to import command at {self.python_name!r}: {e}" 37 ) from e 39 return self.function RuntimeError: Failed to import command at 'napari_ADS._widget:ADSplugin': No module named 'config' ```
Stoyan-I-A commented 1 year ago
File ~/code/napari-plugin/napari-ADS/napari_ADS/_widget.py:6
      4 from pathlib import Path
----> 6 import config
      7 import numpy as np

RuntimeError: Failed to import command at 'napari_ADS._widget:ADSplugin': No module named 'config'

This import line tries to import config.py from AxonDeepSeg. It is possible that AxonDeepSeg was not properly installed.

@jcohenadad Could you type axondeepseg_test in a terminal with the anaconda environment activated which you used for the installation of the napari plugin?

That being said, I don't like the fact that the config file looks like it comes outside of the AxonDeepSeg project as it could be missleading in situations like this one. Thus, I will open an issue on the main AxonDeepSeg github project to address this.

jcohenadad commented 1 year ago

Hum, I guess you're right, probably not properly installed:

julien-macbook:~ $ conda activate ads_venv_napari
(ads_venv_napari) julien-macbook:~ $ axondeepseg_test
-bash: axondeepseg_test: command not found
jcohenadad commented 1 year ago

Reinstalling:

Terminal output ```console (ads_venv_napari) julien-macbook:~/code/axondeepseg-napari $ pip install -e . Obtaining file:///Users/julien/code/axondeepseg-napari Preparing metadata (setup.py) ... done Installing collected packages: AxonDeepSeg Running setup.py develop for AxonDeepSeg Successfully installed AxonDeepSeg-4.1.0 (ads_venv_napari) julien-macbook:~/code/axondeepseg-napari $ axondeepseg_test Computing the segmentation of axon and myelin on test image. 2023-02-18 10:23:52.093 | WARNING | AxonDeepSeg.apply_model:axon_segmentation:49 - The 'no-patch' option was not selected for segmentation. Please note that this option could potentially produce better results but may not be suitable with large images depending on computer RAM capacity. 2023-02-18 10:23:52.093 | INFO | ivadomed.utils:define_device:160 - Cuda is not available. 2023-02-18 10:23:52.093 | INFO | ivadomed.utils:define_device:161 - Working on cpu. 2023-02-18 10:23:52.095 | INFO | ivadomed.config_manager:_display_differing_keys:202 - Adding the following keys to the configuration file 2023-02-18 10:23:52.096 | INFO | ivadomed.config_manager:deep_dict_compare:47 - wandb: {'wandb_api_key': '', 'project_name': 'my_project', 'group_name': 'my_group', 'run_name': 'run-1', 'log_grads_every': 100} 2023-02-18 10:23:52.096 | INFO | ivadomed.config_manager:deep_dict_compare:47 - loader_parameters: patch_filter_params: {'filter_empty_mask': False, 'filter_empty_input': False} 2023-02-18 10:23:52.096 | INFO | ivadomed.config_manager:deep_dict_compare:47 - lr_scheduler: base_lr: 1e-05 2023-02-18 10:23:52.096 | INFO | ivadomed.config_manager:deep_dict_compare:47 - lr_scheduler: max_lr: 0.01 2023-02-18 10:23:52.096 | INFO | ivadomed.config_manager:deep_dict_compare:47 - evaluation_parameters: object_detection_metrics: True 2023-02-18 10:23:52.096 | INFO | ivadomed.config_manager:_display_differing_keys:204 - 2023-02-18 10:23:52.097 | WARNING | ivadomed.inference:segment_volume:409 - fname_roi has not been specified, then the entire volume is processed. 2023-02-18 10:23:52.892 | INFO | ivadomed.loader.mri2d_segmentation_dataset:determine_cache_need:378 - Estimated 2D dataset size is 3.4766271710395813e-06 GB, which is smaller than 6.077123641967773 GB. File cache will not be used 2023-02-18 10:23:52.923 | INFO | ivadomed.inference:segment_volume:477 - Loaded 35 axial patches of shape [256, 256]. 2023-02-18 10:23:52.948 | DEBUG | ivadomed.inference:get_preds:87 - Likely ONNX model detected at: /Users/julien/code/axondeepseg-napari/AxonDeepSeg/models/model_seg_rat_axon-myelin_sem/model_seg_rat_axon-myelin_sem.onnx 2023-02-18 10:23:52.949 | DEBUG | ivadomed.inference:get_preds:88 - Conduct ONNX model inference... 2023-02-18 10:23:54.810 | DEBUG | ivadomed.inference:get_preds:91 - Sending predictions to CPU 2023-02-18 10:23:54.844 | DEBUG | ivadomed.inference:get_preds:87 - Likely ONNX model detected at: /Users/julien/code/axondeepseg-napari/AxonDeepSeg/models/model_seg_rat_axon-myelin_sem/model_seg_rat_axon-myelin_sem.onnx 2023-02-18 10:23:54.844 | DEBUG | ivadomed.inference:get_preds:88 - Conduct ONNX model inference... 2023-02-18 10:23:56.877 | DEBUG | ivadomed.inference:get_preds:91 - Sending predictions to CPU 2023-02-18 10:23:56.910 | DEBUG | ivadomed.inference:get_preds:87 - Likely ONNX model detected at: /Users/julien/code/axondeepseg-napari/AxonDeepSeg/models/model_seg_rat_axon-myelin_sem/model_seg_rat_axon-myelin_sem.onnx 2023-02-18 10:23:56.910 | DEBUG | ivadomed.inference:get_preds:88 - Conduct ONNX model inference... 2023-02-18 10:23:58.630 | DEBUG | ivadomed.inference:get_preds:91 - Sending predictions to CPU 2023-02-18 10:23:58.663 | DEBUG | ivadomed.inference:get_preds:87 - Likely ONNX model detected at: /Users/julien/code/axondeepseg-napari/AxonDeepSeg/models/model_seg_rat_axon-myelin_sem/model_seg_rat_axon-myelin_sem.onnx 2023-02-18 10:23:58.663 | DEBUG | ivadomed.inference:get_preds:88 - Conduct ONNX model inference... 2023-02-18 10:24:00.382 | DEBUG | ivadomed.inference:get_preds:91 - Sending predictions to CPU 2023-02-18 10:24:00.414 | DEBUG | ivadomed.inference:get_preds:87 - Likely ONNX model detected at: /Users/julien/code/axondeepseg-napari/AxonDeepSeg/models/model_seg_rat_axon-myelin_sem/model_seg_rat_axon-myelin_sem.onnx 2023-02-18 10:24:00.414 | DEBUG | ivadomed.inference:get_preds:88 - Conduct ONNX model inference... 2023-02-18 10:24:02.094 | DEBUG | ivadomed.inference:get_preds:91 - Sending predictions to CPU 2023-02-18 10:24:02.120 | DEBUG | ivadomed.inference:get_preds:87 - Likely ONNX model detected at: /Users/julien/code/axondeepseg-napari/AxonDeepSeg/models/model_seg_rat_axon-myelin_sem/model_seg_rat_axon-myelin_sem.onnx 2023-02-18 10:24:02.120 | DEBUG | ivadomed.inference:get_preds:88 - Conduct ONNX model inference... 2023-02-18 10:24:04.340 | DEBUG | ivadomed.inference:get_preds:91 - Sending predictions to CPU 2023-02-18 10:24:04.393 | DEBUG | ivadomed.inference:get_preds:87 - Likely ONNX model detected at: /Users/julien/code/axondeepseg-napari/AxonDeepSeg/models/model_seg_rat_axon-myelin_sem/model_seg_rat_axon-myelin_sem.onnx 2023-02-18 10:24:04.393 | DEBUG | ivadomed.inference:get_preds:88 - Conduct ONNX model inference... 2023-02-18 10:24:07.031 | DEBUG | ivadomed.inference:get_preds:91 - Sending predictions to CPU 2023-02-18 10:24:07.072 | DEBUG | ivadomed.inference:get_preds:87 - Likely ONNX model detected at: /Users/julien/code/axondeepseg-napari/AxonDeepSeg/models/model_seg_rat_axon-myelin_sem/model_seg_rat_axon-myelin_sem.onnx 2023-02-18 10:24:07.072 | DEBUG | ivadomed.inference:get_preds:88 - Conduct ONNX model inference... 2023-02-18 10:24:09.435 | DEBUG | ivadomed.inference:get_preds:91 - Sending predictions to CPU 2023-02-18 10:24:09.462 | DEBUG | ivadomed.inference:get_preds:87 - Likely ONNX model detected at: /Users/julien/code/axondeepseg-napari/AxonDeepSeg/models/model_seg_rat_axon-myelin_sem/model_seg_rat_axon-myelin_sem.onnx 2023-02-18 10:24:09.462 | DEBUG | ivadomed.inference:get_preds:88 - Conduct ONNX model inference... 2023-02-18 10:24:11.216 | DEBUG | ivadomed.inference:get_preds:91 - Sending predictions to CPU Generating axon and myelin segmentation masks and saving. * * * Integrity test passed. AxonDeepSeg is correctly installed. * * * ```

and... the plugin now works like a charm 😊

image

I will be testing it now. Thank you for your excellent support @Stoyan-I-A 🙏

jcohenadad commented 1 year ago

I guess we can close, it was probably a glitch in the installation?

Stoyan-I-A commented 1 year ago

I guess we can close, it was probably a glitch in the installation?

Not sure, but I'm glad you managed to make it work 🙂