I'm trying to set up Jupyter Lab (4.0.11) environment for mayavi 4.8.1 on a remote server.
First of all, I note that
%env QT_QPA_PLATFORM=offscreen
should be set before importing mlab. Otherwise importing mlab crashes. Then
from mayavi import mlab
mlab.init_notebook('itk')
runs fine. However
s = mlab.test_plot3d()
s
gives the following error messages depending on the installation method:
conda install -c conda-forge itkwidgets which installs itkwidgets=0.32.6
[Open Browser Console for more detailed log - Double click to close this message]
Failed to load model class 'ViewerModel' from module 'itkwidgets'
@http://127.0.0.1:9001/lab/extensions/@jupyter-widgets/jupyterlab-manager/static/134.a63a8d293fb35a52dc25.js:1:74945
loadClass@http://127.0.0.1:9001/lab/extensions/@jupyter-widgets/jupyterlab-manager/static/134.a63a8d293fb35a52dc25.js:1:75302
@http://127.0.0.1:9001/lab/extensions/@jupyter-widgets/jupyterlab-manager/static/336.ebc7a55ea1768712771f.js:1:10738
loadModelClass@http://127.0.0.1:9001/lab/extensions/@jupyter-widgets/jupyterlab-manager/static/336.ebc7a55ea1768712771f.js:1:10890
@http://127.0.0.1:9001/lab/extensions/@jupyter-widgets/jupyterlab-manager/static/336.ebc7a55ea1768712771f.js:1:7531
_make_model@http://127.0.0.1:9001/lab/extensions/@jupyter-widgets/jupyterlab-manager/static/336.ebc7a55ea1768712771f.js:1:8204
@http://127.0.0.1:9001/lab/extensions/@jupyter-widgets/jupyterlab-manager/static/336.ebc7a55ea1768712771f.js:1:5148
new_model@http://127.0.0.1:9001/lab/extensions/@jupyter-widgets/jupyterlab-manager/static/336.ebc7a55ea1768712771f.js:1:5194
handle_comm_open@http://127.0.0.1:9001/lab/extensions/@jupyter-widgets/jupyterlab-manager/static/336.ebc7a55ea1768712771f.js:1:3903
@http://127.0.0.1:9001/lab/extensions/@jupyter-widgets/jupyterlab-manager/static/134.a63a8d293fb35a52dc25.js:1:73489
@http://127.0.0.1:9001/lab/extensions/@jupyter-widgets/jupyterlab-manager/static/134.a63a8d293fb35a52dc25.js:1:73495
@http://127.0.0.1:9001/static/lab/jlab_core.33f047ff2ca794a7104f.js:1:1242535
pip install 'itkwidgets[all]>=1.0a23' which installs itkwidgets=1.0a48
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
File ~/anaconda3/envs/mayavi/lib/python3.11/site-packages/IPython/core/formatters.py:922, in IPythonDisplayFormatter.__call__(self, obj)
920 method = get_real_method(obj, self.print_method)
921 if method is not None:
--> 922 method()
923 return True
File ~/anaconda3/envs/mayavi/lib/python3.11/site-packages/mayavi/tools/notebook.py:31, in _ipythondisplay(self)
22 def _ipythondisplay(self):
23 '''Method attached to Mayavi objects.
24
25 Note that here self is the Mayavi object that is going to be
(...)
29
30 '''
---> 31 return _backend.display(self)
File ~/anaconda3/envs/mayavi/lib/python3.11/site-packages/mayavi/tools/notebook.py:145, in ITKBackend.display(self, obj)
137 # Works around bug in released itkwidgets-0.32.1.
138 # Can remove when this PR is merged and in a release:
139 # https://github.com/InsightSoftwareConsortium/itkwidgets/pull/438
140 kw = dict(
141 actors=actors, geometries=[], geometry_colors=[],
142 geometry_opacities=[], point_sets=[], point_set_colors=[],
143 point_set_opacities=[]
144 )
--> 145 return idisplay(self._view(**kw))
146 else:
147 return obj
File ~/anaconda3/envs/mayavi/lib/python3.11/site-packages/itkwidgets/viewer.py:1544, in view(data, kwargs)
1414 def view(data=None, kwargs):
1415 """View the image and/or point set.
1416
1417 Creates and returns an ImJoy plugin ipywidget to visualize an image, and/or
(...)
1542 :rtype: Viewer
1543 """
-> 1544 viewer = Viewer(data=data, **kwargs)
1546 return viewer
File ~/anaconda3/envs/mayavi/lib/python3.11/site-packages/itkwidgets/_initialization_params.py:100, in build_init_data(input_data, stores)
98 result = _get_viewer_point_set(data)
99 if result is None:
--> 100 raise RuntimeError(f"Could not process the viewer {input_type}")
101 input_data[render_type.value] = result
102 return input_data
RuntimeError: Could not process the viewer data
<mayavi.modules.surface.Surface at 0x2b261dd19fd0>
There is already report on the same problem https://github.com/enthought/mayavi/issues/1202#issue-1531272998 without any solution.
And I encountered the same error even in my laptop (MacBook Pro).
How do I obtain desired behavior of mayavi with itkwidgets?
Thanks in advance.
I'm trying to set up Jupyter Lab (4.0.11) environment for mayavi 4.8.1 on a remote server.
First of all, I note that
should be set before importing
mlab
. Otherwise importingmlab
crashes. Thenruns fine. However
gives the following error messages depending on the installation method:
conda install -c conda-forge itkwidgets
which installsitkwidgets=0.32.6
pip install 'itkwidgets[all]>=1.0a23'
which installsitkwidgets=1.0a48
File ~/anaconda3/envs/mayavi/lib/python3.11/site-packages/mayavi/tools/notebook.py:31, in _ipythondisplay(self) 22 def _ipythondisplay(self): 23 '''Method attached to Mayavi objects. 24 25 Note that here
self
is the Mayavi object that is going to be (...) 29 30 ''' ---> 31 return _backend.display(self)File ~/anaconda3/envs/mayavi/lib/python3.11/site-packages/mayavi/tools/notebook.py:145, in ITKBackend.display(self, obj) 137 # Works around bug in released itkwidgets-0.32.1. 138 # Can remove when this PR is merged and in a release: 139 # https://github.com/InsightSoftwareConsortium/itkwidgets/pull/438 140 kw = dict( 141 actors=actors, geometries=[], geometry_colors=[], 142 geometry_opacities=[], point_sets=[], point_set_colors=[], 143 point_set_opacities=[] 144 ) --> 145 return idisplay(self._view(**kw)) 146 else: 147 return obj
File ~/anaconda3/envs/mayavi/lib/python3.11/site-packages/itkwidgets/viewer.py:1544, in view(data, kwargs) 1414 def view(data=None, kwargs): 1415 """View the image and/or point set. 1416 1417 Creates and returns an ImJoy plugin ipywidget to visualize an image, and/or (...) 1542 :rtype: Viewer 1543 """ -> 1544 viewer = Viewer(data=data, **kwargs) 1546 return viewer
File ~/anaconda3/envs/mayavi/lib/python3.11/site-packages/itkwidgets/viewer.py:191, in Viewer.init(self, ui_collapsed, rotate, ui, **add_data_kwargs) 189 self.name = self.str() 190 input_data = parse_input_data(add_data_kwargs) --> 191 data = build_init_data(input_data, self.stores) 192 if compare := input_data.get('compare'): 193 data['compare'] = compare
File ~/anaconda3/envs/mayavi/lib/python3.11/site-packages/itkwidgets/_initialization_params.py:100, in build_init_data(input_data, stores) 98 result = _get_viewer_point_set(data) 99 if result is None: --> 100 raise RuntimeError(f"Could not process the viewer {input_type}") 101 input_data[render_type.value] = result 102 return input_data
RuntimeError: Could not process the viewer data
<mayavi.modules.surface.Surface at 0x2b261dd19fd0>