Search code examples
pythonwindowsvtkmayavi

Mayavi window stop showing up


I've been using mayavi in python 3.5 and on a windows 10 machine. Today I was working on some script using mayavi and for no reason (that I know) the mayavi visualization window stopped showing up. In fact any mayavi example doesn't show the visualization window anymore. The scripts would wait on the mlab.show() but they won't show anything.

I've tried the following but it still doesn't show the visualization window (each time just waiting at the mlab.show() command):

  • Restart the machine and try again.
  • pip install --upgrade for mayavi, vtk and pyQt4, then try again.
  • I created a new virtualenv and install numpy, pyQt4, vtk, mayavi , then try again.
  • I run the boy.py example with mlab.show(stop=True). The stop=True shows a window with a button "stop interaction" to finish the event loop. I see this window but not the visualization window. I thought maybe the window is there but hidden. I found WinLister which allows you to show all windows. I can see that the last opened windows are two QWidget, one is for the window with the close button and it shows as visible, and the other shows as not visible. I switch that window to visible and I see a window that could be the mayavi visualization window but it's all blank.
  • If I step through the call to mlab.show() I see it eventually goes to the function start_event_loop_qt4() in site-packages/pyface/utils/guisupport.py and it waits indefinitely in the call to app.exec_(), nothing else happens.
  • I've install a new Python 3.5.2, create a new virtual enviroment and install numpy, pyQt4, vtk, mayavi , then try again, same problem.
  • I went to another machine and install numpy, pyQt4, vtk, mayavi and the examples worked well (just checking I'm not going crazy).

Probably unrelated, but the last thing I was doing before the window stop showing up was recording a script from the mayavi properties window, I wanted to see what commands correspond to moving the viewpoint to a certain place. Once I saw the commands being recorded, I copied them and close the mayavi visualization window without stopping the recording. From that moment onwards I experienced the described problem.

UPDATE:

I've been debugging the boy.py example on the machine that works and on the one that doesn't (both machines have the same software configuration) and I've found the first point in which their execution deviates.

When creating a figure:

mlab.figure(fgcolor=(0, 0, 0), bgcolor=(1, 1, 1))

the machine that works opens an empty vtk/mayavi window, the machine that doesn't work doesn't open anything.

I step through the figure function (in the machine that doesn't work) and I found that at this point in the execution stack it starts to deviate:

boy.py,  line 23
  mlab.figure(fgcolor=(0, 0, 0), bgcolor=(1, 1, 1))
figure.py,  line 68, in figure
  engine.new_scene(name=name, size=size)
recordable.py,  line 45, in _wrapper
  result = func(*args, **kw)
engine.py,  line 452, in new_scene
  viewer = self.scene_factory(**factory_kwargs)

viewer is a mayavi.core.null_engine.DummyViewer object, where as in the machine it works viewer is a mayavi.core.ui.mayavi_scene.MayaviViewer object

I also find that the factory_kwargs passed to self.scene_factory is {} in the machine it doesn't work, and it's {'size': (400,350)} in the machine it works.

I'm trying to understand how the scene_factory works but it's a bit daunting task.


Solution

  • I found a solution!

    Stepping through the code for mlab.figure() I found that at this point in the execution stack:

    boy.py,  line 23
      mlab.figure(fgcolor=(0, 0, 0), bgcolor=(1, 1, 1))
    figure.py,  line 63, in figure
      engine = get_engine()
    engine_manager.py,  line 101, in get_engine
      return self.new_engine()
    engine_manager.py,  line 154, in new_engine
      elif options.backend == 'test':
    

    the backend was 'test' which instantiates a

    engine = NullEngine(name='Null Mlab Engine')
    

    in the machine that works the backend was 'auto' and it instantiates a

    engine = Engine(name='Mlab Engine')
    

    So I searched for how this backend is set, something related with the mayavi.preferences.prefence_manager.py I saw that in the same folder there is a preferences.ini . However, it already had a variable set as backend ='auto' .

    Then I found that the script mayavi.scripts.mayavi2.py shows a data visualizer. If we select the menu option Tools/Preferences/Mayavi/Mlab the field backend was set to 'test'. I changed it to 'auto' and then the mayavi boy.py example started to work again!

    One confusing thing is that then I went back to my original Python 3.5 installation and my original virtualenv. I run the boy.py example and it worked without having to do anything on that installation. So I suspect that these settings are being stored somewhere else outside the python or virtualenv folders, maybe in the windows registry? That is why re-installing mayavi, even in a new virtualenv and with a new python installation didn't solve the problem!

    I'm not sure how the backend changed, maybe I changed it myself while experimenting with mayavi. However, I think these preferences shouldn't be persistent outside the virtualenv or the python installation in use.