haesleinhuepf / napari-tools-menu

BSD 3-Clause "New" or "Revised" License
9 stars 2 forks source link

Error in monkey patching (no _qt import) #1

Open aeisenbarth opened 3 years ago

aeisenbarth commented 3 years ago

I get an exception when using napari-tools-menu 0.1.4 in napari 0.4.11.

After adding print_exc() at the end of the except block (which is maybe good practice), I get more insight:

…/miniconda3/envs/spacem/lib/python3.8/site-packages/napari_tools_menu/__init__.py:124: UserWarning: Error in monkey patching napari. Please let @haesleinleinhuepf know at
https://github.com/haesleinhuepf/napari-tools-menu/issues
  warnings.warn("Error in monkey patching napari. Please let @haesleinleinhuepf know at\nhttps://github.com/haesleinhuepf/napari-tools-menu/issues")
Traceback (most recent call last):
  File "…/miniconda3/envs/spacem/lib/python3.8/site-packages/napari_tools_menu/__init__.py", line 107, in <module>
    if not hasattr(napari._qt.qt_main_window._QtMainWindow.__class__, "_add_menus_bkp"):
  File "…/miniconda3/envs/spacem/lib/python3.8/site-packages/napari/_lazy.py", line 50, in __getattr__
    raise AttributeError(f'No {module_name} attribute {name}')
AttributeError: No napari attribute _qt

I don't see that _qt is exported in my napari/__init__.py

Adding import napari._qt in the top of napari_tools_menu/__init__.py solves it.

haesleinhuepf commented 3 years ago

Thanks @aeisenbarth for reporting!

Adding import napari._qt in the top of napari_tools_menu/init.py solves it.

I couldn't reproduce the issue on my system (neither on napari 0.4.11 nor on 0.4.12), but adding this line also doesn't hurt. Thus, I just released napari-tools-menu 0.1.5 with your suggestion. Would you mind installing it on your machine and reporting back if that solves the problem?

Thanks!

Best, Robert