Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attempting to open up an interactive viewer --> ImportError: cannot import name 'metadata' from 'importlib' #244

Open
eldad-a opened this issue Sep 9, 2022 · 2 comments

Comments

@eldad-a
Copy link

eldad-a commented Sep 9, 2022

  • npe2 version: 0.3.0
  • Python version: 3.7.12
  • Operating System: Linux 5.19.0-76051900-generic

Description

Attempting to open up a napari interactive viewer window fails with ImportError exception, both from command-line and jupyterlab.

Downgrading npe2 from 0.3.0 to 0.2.2 or 0.1.1 resolves for me; for example using conda:

conda install npe2=0.1.1

haven't tested other newer versions.

Issue may be related to importlib.metadata issue on import (Python 3.7 & Linux) #4747

What I Did

CLI:

napari

Exception

Traceback (most recent call last):                                                                        
  File "/home/UserName/lib/python/miniconda3/envs/hvDataLab/bin/napari", line 6, in <module>                                                                                                                          
    from napari.__main__ import main                                                                      
  File "/home/UserName/lib/python/miniconda3/envs/hvDataLab/lib/python3.7/site-packages/napari/__main__.py", line 15, in <module>
    import napari.plugins._npe2 as _npe2                                                                  
  File "/home/UserName/lib/python/miniconda3/envs/hvDataLab/lib/python3.7/site-packages/napari/plugins/__init__.py", line 3, in <module>                                                                              
    from npe2 import PluginManager as _PluginManager                                                      
  File "/home/UserName/lib/python/miniconda3/envs/hvDataLab/lib/python3.7/site-packages/npe2/__init__.py", line 8, in <module>
    from ._dynamic_plugin import DynamicPlugin                                                            
  File "/home/UserName/lib/python/miniconda3/envs/hvDataLab/lib/python3.7/site-packages/npe2/_dynamic_plugin.py", line 19, in <module>
    from ._plugin_manager import PluginManager                                                            
  File "/home/UserName/lib/python/miniconda3/envs/hvDataLab/lib/python3.7/site-packages/npe2/_plugin_manager.py", line 7, in <module>
    from importlib import metadata                                                                        
ImportError: cannot import name 'metadata' from 'importlib' (/home/UserName/lib/python/miniconda3/envs/hvDataLab/lib/python3.7/importlib/__init__.py)

JLab

import os
os.environ['DISPLAY'] = ':1.0' ## get from `env |grep DISPLAY`
%gui qt5

from skimage import data
import napari

viewer = napari.view_image(data.astronaut(), rgb=True)

Exception

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
/tmp/ipykernel_722701/837316459.py in <module>
      2 import napari
      3 
----> 4 viewer = napari.view_image(data.astronaut(), rgb=True)

~/lib/python/miniconda3/envs/hvDataLab/lib/python3.7/site-packages/napari/_lazy.py in __getattr__(name)
     45             return import_module(f'{module_name}.{name}')
     46         elif name in attr_to_modules:
---> 47             submod = import_module(f'{module_name}.{attr_to_modules[name]}')
     48             return getattr(submod, name)
     49         else:

~/lib/python/miniconda3/envs/hvDataLab/lib/python3.7/importlib/__init__.py in import_module(name, package)
    125                 break
    126             level += 1
--> 127     return _bootstrap._gcd_import(name[level:], package, level)
    128 
    129 

~/lib/python/miniconda3/envs/hvDataLab/lib/python3.7/importlib/_bootstrap.py in _gcd_import(name, package, level)

~/lib/python/miniconda3/envs/hvDataLab/lib/python3.7/importlib/_bootstrap.py in _find_and_load(name, import_)

~/lib/python/miniconda3/envs/hvDataLab/lib/python3.7/importlib/_bootstrap.py in _find_and_load_unlocked(name, import_)

~/lib/python/miniconda3/envs/hvDataLab/lib/python3.7/importlib/_bootstrap.py in _load_unlocked(spec)

~/lib/python/miniconda3/envs/hvDataLab/lib/python3.7/importlib/_bootstrap_external.py in exec_module(self, module)

~/lib/python/miniconda3/envs/hvDataLab/lib/python3.7/importlib/_bootstrap.py in _call_with_frames_removed(f, *args, **kwds)

~/lib/python/miniconda3/envs/hvDataLab/lib/python3.7/site-packages/napari/view_layers.py in <module>
     19 from napari.components.dims import Dims
     20 
---> 21 from .viewer import Viewer
     22 
     23 __all__ = [

~/lib/python/miniconda3/envs/hvDataLab/lib/python3.7/site-packages/napari/viewer.py in <module>
      5 import magicgui as mgui
      6 
----> 7 from .components.viewer_model import ViewerModel
      8 from .utils import _magicgui, config
      9 

~/lib/python/miniconda3/envs/hvDataLab/lib/python3.7/site-packages/napari/components/__init__.py in <module>
     17 from .camera import Camera
     18 from .dims import Dims
---> 19 from .layerlist import LayerList
     20 
     21 # Note that importing _viewer_key_bindings is needed as the Viewer gets

~/lib/python/miniconda3/envs/hvDataLab/lib/python3.7/site-packages/napari/components/layerlist.py in <module>
      6 import numpy as np
      7 
----> 8 from ..layers import Layer
      9 from ..layers.image.image import _ImageBase
     10 from ..utils.context import create_context

~/lib/python/miniconda3/envs/hvDataLab/lib/python3.7/site-packages/napari/layers/__init__.py in <module>
     10 from ..utils.misc import all_subclasses as _all_subcls
     11 from .base import Layer
---> 12 from .image import Image
     13 from .labels import Labels
     14 from .points import Points

~/lib/python/miniconda3/envs/hvDataLab/lib/python3.7/site-packages/napari/layers/image/__init__.py in <module>
----> 1 from . import _image_key_bindings
      2 from .image import Image
      3 
      4 # Note that importing _image_key_bindings is needed as the Image layer gets
      5 # decorated with keybindings during that process, but it is not directly needed

~/lib/python/miniconda3/envs/hvDataLab/lib/python3.7/site-packages/napari/layers/image/_image_key_bindings.py in <module>
      4 from ...utils.translations import trans
      5 from ._image_constants import Mode
----> 6 from .image import Image
      7 
      8 

~/lib/python/miniconda3/envs/hvDataLab/lib/python3.7/site-packages/napari/layers/image/image.py in <module>
     10 from scipy import ndimage as ndi
     11 
---> 12 from ...utils import config
     13 from ...utils._dtype import get_dtype_limits, normalize_dtype
     14 from ...utils.colormaps import AVAILABLE_COLORMAPS

~/lib/python/miniconda3/envs/hvDataLab/lib/python3.7/site-packages/napari/utils/config.py in <module>
      3 import os
      4 
----> 5 from ._octree import get_octree_config
      6 
      7 

~/lib/python/miniconda3/envs/hvDataLab/lib/python3.7/site-packages/napari/utils/_octree.py in <module>
      9 from typing import Optional
     10 
---> 11 from ..settings import get_settings
     12 from ..utils.translations import trans
     13 

~/lib/python/miniconda3/envs/hvDataLab/lib/python3.7/site-packages/napari/settings/__init__.py in <module>
      4 from ..utils.translations import trans
      5 from ._base import _NOT_SET
----> 6 from ._napari_settings import NapariSettings
      7 
      8 __all__ = ['NapariSettings', 'get_settings']

~/lib/python/miniconda3/envs/hvDataLab/lib/python3.7/site-packages/napari/settings/_napari_settings.py in <module>
      7 from ..utils._base import _DEFAULT_CONFIG_PATH
      8 from ..utils.translations import trans
----> 9 from ._appearance import AppearanceSettings
     10 from ._application import ApplicationSettings
     11 from ._base import EventedConfigFileSettings

~/lib/python/miniconda3/envs/hvDataLab/lib/python3.7/site-packages/napari/settings/_appearance.py in <module>
      2 
      3 from ..utils.events.evented_model import EventedModel
----> 4 from ..utils.theme import available_themes
      5 from ..utils.translations import trans
      6 from ._fields import Theme

~/lib/python/miniconda3/envs/hvDataLab/lib/python3.7/site-packages/napari/utils/theme.py in <module>
    333 
    334 
--> 335 _install_npe2_themes(_themes)
    336 _themes.events.added.connect(rebuild_theme_settings)
    337 _themes.events.removed.connect(rebuild_theme_settings)

~/lib/python/miniconda3/envs/hvDataLab/lib/python3.7/site-packages/napari/utils/theme.py in _install_npe2_themes(_themes)
    323 # this function here instead of plugins._npe2 to avoid circular import
    324 def _install_npe2_themes(_themes):
--> 325     import npe2
    326 
    327     for theme in npe2.PluginManager.instance().iter_themes():

~/lib/python/miniconda3/envs/hvDataLab/lib/python3.7/site-packages/npe2/__init__.py in <module>
      6 __email__ = "[email protected]"
      7 
----> 8 from ._dynamic_plugin import DynamicPlugin
      9 from ._plugin_manager import PluginContext, PluginManager
     10 from .io_utils import read, read_get_reader, write, write_get_writer

~/lib/python/miniconda3/envs/hvDataLab/lib/python3.7/site-packages/npe2/_dynamic_plugin.py in <module>
     17 from typing_extensions import Literal
     18 
---> 19 from ._plugin_manager import PluginManager
     20 from .manifest.contributions import (
     21     CommandContribution,

~/lib/python/miniconda3/envs/hvDataLab/lib/python3.7/site-packages/npe2/_plugin_manager.py in <module>
      5 from collections import Counter
      6 from fnmatch import fnmatch
----> 7 from importlib import metadata
      8 from pathlib import Path
      9 from typing import (

ImportError: cannot import name 'metadata' from 'importlib' (/home/eldada/lib/python/miniconda3/envs/hvDataLab/lib/python3.7/importlib/__init__.py)

Additional versions info that may be of relevance

Python implementation: CPython
Python version       : 3.7.12
IPython version      : 7.33.0

jupyterlab        : 3.4.6

napari: 0.4.14

Linux 5.19.0-76051900-generic #202207312230~1660780566~22.04~9d60db1 SMP PREEMPT_DYNAMIC Thu A x86_64 x86_64 x86_64 GNU/Linux
@tlambert03
Copy link
Collaborator

I'm afraid python 3.7 is no longer supported

@Czaki
Copy link
Collaborator

Czaki commented Oct 11, 2022

For people who will looking for a solution, you will need to use importlib-metadata<4.12.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants