mehta-lab / waveorder

Wave optical models and inverse algorithms for label-agnostic imaging of density & orientation.
BSD 3-Clause "New" or "Revised" License
15 stars 4 forks source link

`napari.Viewer()` fails after `import waveorder` in OnDemand session #97

Closed talonchandler closed 1 year ago

talonchandler commented 1 year ago

In an OnDemand session with waveorder installed (in the shared recOrder environment or the current main branch):

python
>>> import napari
>>> v = napari.Viewer() 

will open a napari window as expected. If instead you try

python 
>>> import waveorder
>>> import napari
>>> v = napari.Viewer()

napari does not open and you'll receive a message:

WARNING: QObject::moveToThread: Current thread (0x557aa28ed750) is not the object's thread (0x557aa47ffdb0).
Cannot move to target thread (0x557aa28ed750)

Warning: Could not load the Qt platform plugin "xcb" in "/home/talon.chand\
ler/.local/lib/python3.8/site-packages/cv2/qt/plugins" even though it was \
found.
WARNING: This application failed to start because no Qt platform plugin co\
uld be initialized. Reinstalling the application may fix this problem.

Available platform plugins are: xcb, eglfs, linuxfb, minimal, minimalegl, \
offscreen, vnc, wayland-egl, wayland, wayland-xcomposite-egl, wayland-xcom\
posite-glx, webgl.

Changing the order of imports is workable for scripts, but not always convenient. This issue also might be causing issues in recOrder see: https://github.com/mehta-lab/recOrder/issues/109

ziw-liu commented 1 year ago

This is a somewhat frequent issue on HPC with OpenCV Qt components. A work around is to use specific Qt and OpenCV versions. However in our case cv2 is only used once to encode byte streams (and the function name ('JPG') is confusingly inconsistent with the actual code ('PNG')):

https://github.com/mehta-lab/waveorder/blob/5f60f0ad27e05596a6f6cb09ef2310f6bc00f236/waveorder/visual.py#L36-L40

And this should be easily swapped out with PIL or similar so that we can stop depending on OpenCV.

Edit: we already depend on pillow (PIL fork) through matplotlib.