brainglobe / brainglobe-segmentation

Segmentation of anatomical structures in a common coordinate space
https://brainglobe.info/documentation/brainglobe-segmentation/index.html
BSD 3-Clause "New" or "Revised" License
28 stars 10 forks source link

[BUG] RuntimeError: Failed to import command at 'brainglobe_segmentation.segment:SegmentationWidget': No module named 'brainglobe_utils.image_io' #179

Closed karolinasocha closed 4 months ago

karolinasocha commented 4 months ago

Hi,

I tried to use region/track_segmentation (brainglobe-segmentation) but this error occurs everytime: RuntimeError: Failed to import command at 'brainglobe_segmentation.segment:SegmentationWidget': No module named 'brainglobe_utils.image_io'

I have file after brain registration (brainreg) and wanted to do 3D optical fiber reconstruction. The registered brain loaded normally but I failed to start plugin brainglobe-segmentation.

The full installation was done today, and I have installed package brainglobe-utils 0.5.0 :

image

Any idea how to solve this?

Full Error Message

ModuleNotFoundError                       Traceback (most recent call last)
File D:\IBL\Programs\Anaconda3\envs\brainglobe-env\lib\site-packages\npe2\_command_registry.py:32, in CommandHandler.resolve(self=CommandHandler(id='brainglobe-segmentation.Segme...inglobe_segmentation.segment:SegmentationWidget'))
     31 try:
---> 32     self.function = utils.import_python_name(self.python_name)
        self.function = None
        self.python_name = 'brainglobe_segmentation.segment:SegmentationWidget'
        self = CommandHandler(id='brainglobe-segmentation.SegmentationWidget', function=None, python_name='brainglobe_segmentation.segment:SegmentationWidget')
        utils = <module 'npe2.manifest.utils' from 'D:\\IBL\\Programs\\Anaconda3\\envs\\brainglobe-env\\lib\\site-packages\\npe2\\manifest\\utils.py'>
     33 except Exception as e:

File D:\IBL\Programs\Anaconda3\envs\brainglobe-env\lib\site-packages\npe2\manifest\utils.py:254, in import_python_name(python_name='brainglobe_segmentation.segment:SegmentationWidget')
    252 module_name, funcname = match.groups()  # type: ignore [union-attr]
--> 254 mod = import_module(module_name)
        module_name = 'brainglobe_segmentation.segment'
    255 return getattr(mod, funcname)

File D:\IBL\Programs\Anaconda3\envs\brainglobe-env\lib\importlib\__init__.py:126, in import_module(name='brainglobe_segmentation.segment', package=None)
    125         level += 1
--> 126 return _bootstrap._gcd_import(name[level:], package, level)
        level = 0
        name = 'brainglobe_segmentation.segment'
        name[level:] = 'brainglobe_segmentation.segment'
        package = None
        _bootstrap = <module '_frozen_importlib' (frozen)>

File <frozen importlib._bootstrap>:1050, in _gcd_import(name='brainglobe_segmentation.segment', package=None, level=0)

File <frozen importlib._bootstrap>:1027, in _find_and_load(name='brainglobe_segmentation.segment', import_=<function _gcd_import>)

File <frozen importlib._bootstrap>:1006, in _find_and_load_unlocked(name='brainglobe_segmentation.segment', import_=<function _gcd_import>)

File <frozen importlib._bootstrap>:688, in _load_unlocked(spec=ModuleSpec(name='brainglobe_segmentation.segment...e-packages\\brainglobe_segmentation\\segment.py'))

File <frozen importlib._bootstrap_external>:883, in exec_module(self=<_frozen_importlib_external.SourceFileLoader object>, module=<module 'brainglobe_segmentation.segment' from '...e-packages\\brainglobe_segmentation\\segment.py'>)

File <frozen importlib._bootstrap>:241, in _call_with_frames_removed(f=<built-in function exec>, *args=(<code object <module> at 0x000001772C4A4500, fil...ages\brainglobe_segmentation\segment.py", line 1>, {'BOUNDARIES_STRING': 'Boundaries', 'COLUMN_WIDTH': 150, 'DISPLAY_REGION_INFO': True, 'HEMISPHERES_STRING': 'Hemispheres', 'LOADING_PANEL_ALIGN': 'left', 'List': typing.List, 'Optional': typing.Optional, 'Path': <class 'pathlib.Path'>, 'Paths': <class 'brainglobe_segmentation.paths.Paths'>, 'QFileDialog': <class 'PyQt5.QtWidgets.QFileDialog'>, ...}), **kwds={})

File D:\IBL\Programs\Anaconda3\envs\brainglobe-env\lib\site-packages\brainglobe_segmentation\segment.py:25
     24 from brainglobe_segmentation.paths import Paths
---> 25 from brainglobe_segmentation.regions.IO import (
     26     export_label_layers,
     27     save_label_layers,
     28 )
     30 ### SEGMENTATION

File D:\IBL\Programs\Anaconda3\envs\brainglobe-env\lib\site-packages\brainglobe_segmentation\regions\IO.py:5
      4 from brainglobe_utils.general.pathlib import append_to_pathlib_stem
----> 5 from brainglobe_utils.image_io import to_tiff
      6 from brainglobe_utils.IO.surfaces import marching_cubes_to_obj

ModuleNotFoundError: No module named 'brainglobe_utils.image_io'

The above exception was the direct cause of the following exception:

RuntimeError                              Traceback (most recent call last)
File D:\IBL\Programs\Anaconda3\envs\brainglobe-env\lib\site-packages\napari\_qt\menus\plugins_menu.py:105, in PluginsMenu._add_plugin_actions.<locals>._add_toggle_widget(key=('brainglobe-segmentation', 'Region/track segmentation'), hook_type='dock')
    102     return
    104 if hook_type == 'dock':
--> 105     self._win.add_plugin_dock_widget(*key)
        key = ('brainglobe-segmentation', 'Region/track segmentation')
        self._win = <napari._qt.qt_main_window.Window object at 0x0000017774BE1360>
        self = <napari._qt.menus.plugins_menu.PluginsMenu object at 0x000001777F223640>
    106 else:
    107     self._win._add_plugin_function_widget(*key)

File D:\IBL\Programs\Anaconda3\envs\brainglobe-env\lib\site-packages\napari\_qt\qt_main_window.py:876, in Window.add_plugin_dock_widget(self=<napari._qt.qt_main_window.Window object>, plugin_name='brainglobe-segmentation', widget_name='Region/track segmentation', tabify=False)
    873 Widget = None
    874 dock_kwargs = {}
--> 876 if result := _npe2.get_widget_contribution(plugin_name, widget_name):
        widget_name = 'Region/track segmentation'
        plugin_name = 'brainglobe-segmentation'
        _npe2 = <module 'napari.plugins._npe2' from 'D:\\IBL\\Programs\\Anaconda3\\envs\\brainglobe-env\\lib\\site-packages\\napari\\plugins\\_npe2.py'>
    877     Widget, widget_name = result
    879 if Widget is None:

File D:\IBL\Programs\Anaconda3\envs\brainglobe-env\lib\site-packages\napari\plugins\_npe2.py:136, in get_widget_contribution(plugin_name='brainglobe-segmentation', widget_name='Region/track segmentation')
    134     if contrib.plugin_name == plugin_name:
    135         if not widget_name or contrib.display_name == widget_name:
--> 136             return contrib.get_callable(), contrib.display_name
        contrib = WidgetContribution(command='brainglobe-segmentation.SegmentationWidget', display_name='Region/track segmentation', autogenerate=False)
        contrib.display_name = 'Region/track segmentation'
    137         widgets_seen.add(contrib.display_name)
    138 if widget_name and widgets_seen:

File D:\IBL\Programs\Anaconda3\envs\brainglobe-env\lib\site-packages\npe2\manifest\contributions\_widgets.py:49, in WidgetContribution.get_callable(self=WidgetContribution(command='brainglobe-segmentat...='Region/track segmentation', autogenerate=False), _registry=None)
     46 def get_callable(
     47     self, _registry: Optional[CommandRegistry] = None
     48 ) -> Callable[..., Widget]:
---> 49     func = super().get_callable()
     50     if self.autogenerate:
     51         try:

File D:\IBL\Programs\Anaconda3\envs\brainglobe-env\lib\site-packages\npe2\manifest\utils.py:71, in Executable.get_callable(self=WidgetContribution(command='brainglobe-segmentat...='Region/track segmentation', autogenerate=False), _registry=<npe2._command_registry.CommandRegistry object>)
     68     from npe2._plugin_manager import PluginManager
     70     _registry = PluginManager.instance().commands
---> 71 return _registry.get(self.command)
        _registry = <npe2._command_registry.CommandRegistry object at 0x00000177720E86D0>
        self.command = 'brainglobe-segmentation.SegmentationWidget'
        self = WidgetContribution(command='brainglobe-segmentation.SegmentationWidget', display_name='Region/track segmentation', autogenerate=False)

File D:\IBL\Programs\Anaconda3\envs\brainglobe-env\lib\site-packages\npe2\_command_registry.py:138, in CommandRegistry.get(self=<npe2._command_registry.CommandRegistry object>, id='brainglobe-segmentation.SegmentationWidget')
    136     if id not in self._commands:  # sourcery skip
    137         raise KeyError(f"command {id!r} not registered")
--> 138 return self._commands[id].resolve()
        id = 'brainglobe-segmentation.SegmentationWidget'
        self._commands = {'brainglobe-napari-io.brainreg_read_dir': CommandHandler(id='brainglobe-napari-io.brainreg_read_dir', function=<function brainreg_read_dir at 0x000001770A188A60>, python_name='brainglobe_napari_io.brainreg.reader_dir:brainreg_read_dir'), 'brainglobe-napari-io.brainreg_read_dir_atlas_space': CommandHandler(id='brainglobe-napari-io.brainreg_read_dir_atlas_space', function=None, python_name='brainglobe_napari_io.brainreg.reader_dir_atlas_space:brainreg_read_dir_atlas_space'), 'brainglobe-napari-io.brainmapper_read_dir': CommandHandler(id='brainglobe-napari-io.brainmapper_read_dir', function=None, python_name='brainglobe_napari_io.brainmapper.brainmapper_reader_dir:brainmapper_read_dir'), 'brainglobe-napari-io.cellfinder_read_xml': CommandHandler(id='brainglobe-napari-io.cellfinder_read_xml', function=None, python_name='brainglobe_napari_io.cellfinder.reader_xml:cellfinder_read_xml'), 'brainglobe-napari-io.cellfinder_write_multiple_xml': CommandHandler(id='brainglobe-napari-io.cellfinder_write_multiple_xml', function=None, python_name='brainglobe_napari_io.cellfinder.writer_xml:write_multiple_points_to_xml'), 'brainrender-napari.make_brainrender_widget': CommandHandler(id='brainrender-napari.make_brainrender_widget', function=<class 'brainrender_napari.brainrender_widget.BrainrenderWidget'>, python_name='brainrender_napari.brainrender_widget:BrainrenderWidget'), 'brainglobe-segmentation.SegmentationWidget': CommandHandler(id='brainglobe-segmentation.SegmentationWidget', function=None, python_name='brainglobe_segmentation.segment:SegmentationWidget')}
        self = <npe2._command_registry.CommandRegistry object at 0x00000177720E86D0>
        self._commands[id] = CommandHandler(id='brainglobe-segmentation.SegmentationWidget', function=None, python_name='brainglobe_segmentation.segment:SegmentationWidget')

File D:\IBL\Programs\Anaconda3\envs\brainglobe-env\lib\site-packages\npe2\_command_registry.py:34, in CommandHandler.resolve(self=CommandHandler(id='brainglobe-segmentation.Segme...inglobe_segmentation.segment:SegmentationWidget'))
     32     self.function = utils.import_python_name(self.python_name)
     33 except Exception as e:
---> 34     raise RuntimeError(
        self.python_name = 'brainglobe_segmentation.segment:SegmentationWidget'
        self = CommandHandler(id='brainglobe-segmentation.SegmentationWidget', function=None, python_name='brainglobe_segmentation.segment:SegmentationWidget')
     35         f"Failed to import command at {self.python_name!r}: {e}"
     36     ) from e
     38 return self.function

RuntimeError: Failed to import command at 'brainglobe_segmentation.segment:SegmentationWidget': No module named 'brainglobe_utils.image_io'
adamltyson commented 4 months ago

Hi @karolinasocha, sorry about this. There was a problem with our release process, so the latest version was never released. Can you try updating now with:

pip install brainglobe-segmentation -U

This should fix the issue. I'll close this now, but feel free to reopen if you have any issues.

karolinasocha commented 4 months ago

Thanks for your prompt reply. I just wanted to confirm that this worked. K.