3D figure closed immediately after plotting

Hi, I got a problem when running the mne tutorial codes and the figure closed immediately after plotting. I tried both pyvista and mayavi and got the same result.
It looks like a similar problem like this and this.
And I try ticking “Run with Python Console” box accroding to here, but it doesn’t work.
My environment is conda mne.
Please tell me how to solve this, thanks.

I believe @cbrnr is using PyCharm and might be able to help.

In the meantime, could you please share the output of

import mne


Thanks for your reply. There are my system info:

Platform:      Windows-10-10.0.19042-SP0
Python:        3.9.6 | packaged by conda-forge | (default, Jul 11 2021, 03:37:25) [MSC v.1916 64 bit (AMD64)]
Executable:    D:\Applications\Miniconda3\envs\mne\python.exe
CPU:           Intel64 Family 6 Model 140 Stepping 1, GenuineIntel: 8 cores
Memory:        15.8 GB
mne:           0.23.0
numpy:         1.21.1 {blas=NO_ATLAS_INFO, lapack=lapack}
scipy:         1.7.0
matplotlib:    3.4.2 {backend=module://backend_interagg}
sklearn:       0.24.2
numba:         0.53.1
nibabel:       3.2.1
nilearn:       0.8.0
dipy:          1.4.1
cupy:          Not found
pandas:        1.3.0
mayavi:        4.7.2
pyvista:       0.31.3 {pyvistaqt=0.5.0, OpenGL 4.5.0 - Build via Intel(R) Iris(R) Xe Graphics}
vtk:           9.0.1
PyQt5:         5.12.3

I just tried running a simpler tutorial (right-click the file tab and click ‘Run 20_event_arrays’), and without changing any setting the plot opens. Can you try if this tutorial works for you?

For some reason I cannot run 35_eeg_no_mri.py because:

RuntimeError: Could not load any valid 3D backend: pyvista, mayavi, notebook

I do have pyvista and PyQt5 installed though. @richard any idea?

You sure you’re using the correct environment to run this?

I’m using my own venv with those packages installed.

I didn’t download the tutorials data so I run the method mne.viz.plot_events on my own data and it works well. The events plot on the screen and doesn’t close immediately.

I had the same problem once, after I used the conda mne envs, this error disappeared.

OK, I was missing pyvistaqt – maybe this could be mentioned in the RuntimeError (since I did have pyvista installed)?

Regarding the initial question, all figures open but are closed when the script finishes. However, when I set “Run with Python console” in the run configuration, all figures remain open.

1 Like

No problem here whatsoever on macOS with the conda-forge-based environment and mne-python:main.

When I run viz.plot_events, I could get an expected result——the figure ploted on the window and won’t closed automatically untill the close button was clicked. But when running viz.plot_alignment, the figure just flash across. I wonder how to let the figure stay?
Setting “Run with Python console” seems don’t work for me…

What happens if you simply copy-and-paste your code into an interactive Python window?

Are you sure that you have set it in the correct Run Configuration? Here’s what it looks like for me:


oh, I checked and it works! :rofl: Thank you ~

1 Like

Would be good, care to open an issue?

1 Like

@richard Better error message for 3D plots when pyvistaqt is missing · Issue #9606 · mne-tools/mne-python · GitHub

1 Like