spyder-ide / spyder

Official repository for Spyder - The Scientific Python Development Environment
https://www.spyder-ide.org
MIT License
8.15k stars 1.58k forks source link

Mayavi not working interactively in spyder #17518

Open max3-2 opened 2 years ago

max3-2 commented 2 years ago

Problem Description

There are some issues described which may relate but none that reproduces this behavior so I will give this a try. At least to check if its reproducible on other machines. I have added more detail on a mayavi issue (https://github.com/enthought/mayavi/issues/1127) but to sum it up:

Failure to do the above in either environment leads to backend issues when interacting with the figure. The follwing two codes are working examples in both environments which are expected to work and should before proceeding:

Python

# This is the python console tester
from mayavi import mlab
mlab.test_flow()
mlab.show()

# Now the interpreter blocks and you can proceed to interact with mayavi and the model tree, e.g. add new modules there

iPython

# This is the !i!python console tester
from mayavi import mlab
%gui qt

mlab.test_flow()

# Now the interpreter is still active and you can proceed to interact with mayavi and the model tree, e.g. add new modules there or code in new modules. Both will work

What steps reproduce the problem?

Assuming the ipython version, the behavior should be the same in spyder as the example above. However this is not the case. Initially, after importing, spyder reports a message:

[1]: from mayavi import mlab
Changing backend to Qt for Mayavi
[2]: 

Then, using the ipython version above will show the error initially reported in the mayavi issue, e.g. the event loop will not handle mayavi inputs. Adding mlab.show() to combine both soultions, e.g.

from mayavi import mlab
%gui qt  # You can test with and without this line, wont change the issue

mlab.test_flow()
mlab.show()

will actually block the spyder console and the interactive mayavi works as in a default python console. However, after closing the mayavi figure, the console is blocked and needs a hard reset (this is obviously not the case when running the example in a default python console)

Running the example for iypthon in jupyter qtconsole works as expected.

This is reported for win10 and the versions below. I do not have this issue running macOS.

Versions

ccordoba12 commented 2 years ago

Hey @max3-2, thanks for reporting. On Linux I found that mlab.show() blocks not only Spyder, but also IPython and qtconsole.

Furthermore, it seems unnecessary because according to its docs:

Start interacting with the figure.

By default, this function simply creates a GUI and starts its
event loop if needed.

But the figure is created and I can interact with it after I run mlab.test_flow(). Is that not the case for you on Windows?

max3-2 commented 2 years ago

@ccordoba12 Sorry I probably wasn't clear enough on this one. Interacting does indeed work for the figure, but not the tree. This is a feature which I really came to like in interactive data analysis since you can add more plots and visualization on the go. So, to reproduce (again I'm sorry that I can't screen share right now from my windows machine)

  1. Create a mayavi figure using the examples above
  2. Open the tree view (pipeline), e.g. upper left icon in figure toolbar
  3. Interact, e.g. add a module or delete, rename...: A simple test would be renaming Streamline or adding Module->Vectors to VectorField by right-clicking
  4. See an error related to unpacking None due to missing event loop, cf.https://github.com/enthought/traitsui/issues/1853
ccordoba12 commented 2 years ago

Ok, I tried the steps you mentioned above and got this error in the IPython console:

Traceback (most recent call last):
  File "/home/carlos/miniconda3/envs/spyder-stable-cf/lib/python3.7/site-packages/pyface/ui/qt4/action/action_item.py", line 184, in _qt4_on_triggered
    self.controller.perform(action, action_event)
  File "/home/carlos/miniconda3/envs/spyder-stable-cf/lib/python3.7/site-packages/traitsui/qt4/tree_editor.py", line 1166, in perform
    self.ui.do_undoable(self._perform, action)
  File "/home/carlos/miniconda3/envs/spyder-stable-cf/lib/python3.7/site-packages/traitsui/ui.py", line 645, in do_undoable
    action(*args, **kw)
  File "/home/carlos/miniconda3/envs/spyder-stable-cf/lib/python3.7/site-packages/traitsui/qt4/tree_editor.py", line 1169, in _perform
    node, object, nid = self._data
TypeError: cannot unpack non-iterable NoneType object

However, this error is not related to Spyder in any way. So, I'd say if you can reproduce it in a Jupyter notebook, it has to do with the Jupyter architecture and not with Spyder.

Please do that and let us know how that goes.

max3-2 commented 2 years ago

That is the error I am talking about. As stated above,

Running the example for iypthon in ´jupyter qtconsole´ works as expected.

Currently I think something with the spider gui loop might interfere but I have zero idea how to track that down.

max3-2 commented 2 years ago

@ccordoba12 Could you verify that this works in qtconsole? If yes, I do see the issue on the side of spyder and would be happy to help if you can give me a rough direction on how to debug a frozen console, e.g. showing the "last call"

max3-2 commented 1 year ago

@ccordoba12 Bumping this since its somewhat still the same issue as described above. Working in python, ipython and jupyer qtconsole, but in spyder I try

from mayavi import mlab
mlab.test_flow()

or

from mayavi import mlab
%gui qt

both lead to a full block of the console with a needed kernel restart. Can't interrupt or use SIGINT so no errors are reported. Any way to proceed? If you tell me how I can try to get error logs but I think it just hangs at this point

Also: I can do

%gui qt

and keep using spyder but as soon as I call from mayavi import mlab the block occurs