napari / napari-animation

A napari plugin for making animations
https://napari.github.io/napari-animation/
Other
74 stars 27 forks source link

Import Error #177

Closed xwyan1230 closed 7 months ago

xwyan1230 commented 1 year ago

I'm at the very early step of trying set this up but came across this error msg. Wonder if anybody might have any quick thought!

ImportError: cannot import name 'version' from 'napari._version' (/....../python3.9/site-packages/napari/_version.py)

Thanks!

jni commented 1 year ago

it's quite hard to debug just from that. Can you let us know:

xwyan1230 commented 1 year ago

Thank you for the prompt response. I'm not sure what are the necessary information needed, but here're the answers:

  1. napari installing conda create -y -n my_env -c conda-forge python=3.9 conda activate my_env python -m pip install “napari[all]”

  2. napari-animation installing pip install napari-animation

  3. when see the error msg I try to run from napari_animation import Animation

Thank you so much! Let me know if you need additional information!

jni commented 1 year ago

Thanks! Can you also share the full error message?

Also, does running napari --info work? 🤞 😬

xwyan1230 commented 1 year ago

Yes! full error msg here (I masked some personal information in the path) Traceback (most recent call last): File "/Users/.../03_20230706_img-check_3d-seg.py", line 6, in from napari_animation import Animation File "/Users/.../opt/anaconda3/envs/my_env/lib/python3.9/site-packages/napari_animation/init.py", line 1, in from ._qt import AnimationWidget File "/Users/.../opt/anaconda3/envs/my_env/lib/python3.9/site-packages/napari_animation/_qt/init.py", line 1, in from .animation_widget import AnimationWidget File "/Users/.../opt/anaconda3/envs/my_env/lib/python3.9/site-packages/napari_animation/_qt/animation_widget.py", line 13, in from ..animation import Animation File "/Users/.../opt/anaconda3/envs/my_env/lib/python3.9/site-packages/napari_animation/animation.py", line 8, in from napari._version import version as napari_version ImportError: cannot import name 'version' from 'napari._version' (/Users/.../opt/anaconda3/envs/my_env/lib/python3.9/site-packages/napari/_version.py)

napari --info napari: 0.4.16 Platform: macOS-10.16-x86_64-i386-64bit System: MacOS 13.3.1 Python: 3.9.0 | packaged by conda-forge | (default, Oct 14 2020, 22:56:29) [Clang 10.0.1 ] Qt: 5.15.2 PyQt5: 5.15.6 NumPy: 1.23.3 SciPy: 1.9.1 Dask: 2022.05.2 VisPy: 0.10.0

OpenGL:

Screens:

Plugins:

alisterburt commented 1 year ago

hi @xwyan1230 - this looks like an error relating to your napari install itself rather than something specific to napari-animation. Could you confirm that you can open a napari viewer (either programmatically from Python or by typing napari at the shell prompt?)

xwyan1230 commented 1 year ago

@alisterburt Yes! I confirm that napari works perfectly fine! If you think this is the issue, is there any recommended way to install napari and napari-animation? I’d happy to set up a new environment to give it a try!

psobolewskiPhD commented 8 months ago

Bit late to the party, so hopefully this isn't an actual issue anymore, but I can reproduce this with napari 0.4.16 and animation 0.0.7 caused by https://github.com/napari/napari-animation/pull/167 On 0.4.16 _version.py uses version and not __version__ With napari 0.4.17 and onwards it's __version__

So I think to prevent this in the case of someone using an older napari for whatever reason, either we need to have napari>=0.4.17 in setup or alter the version checking logic to the more canonical:

from importlib.metadata import version
...
napari_version = version('napari')

This works as expected for all versions of napari I tested.

jni commented 7 months ago

Wasn't there an issue with importlib_metadata and older Python versions, though? That word combination is triggering for me for some reason. 😂 But anyway, that seems easy enough and seems at least as good as hardcoding __version__ going forward, so let's go with it!

psobolewskiPhD commented 7 months ago

According to https://docs.python.org/3/library/importlib.metadata.html#module-importlib.metadata importlib.metadata is from python 3.8. I think napari dropped 3.7 in 0.4.15. importlib_metadata is a backport, but I think it would need to be installed. Honestly, the watermarking is pretty optional and not important to functionality, so could try/except and return a value like old or something?