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

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

I tried installing both pyvista and mayavi. When I import them, in my jupyter notebook, I get below error:
ImportError: Failed to load vtkInteractionWidgets: No module named vtkmodules.vtkRenderingCore

Below is my mne.sys_info()
Platform: Windows-10-10.0.19041-SP0
Python: 3.8.5 (default, Sep 3 2020, 21:29:08) [MSC v.1916 64 bit (AMD64)]
Executable: C:\Users\harsh\anaconda3\envs\gputensorflow\python.exe
CPU: Intel64 Family 6 Model 158 Stepping 10, GenuineIntel: 12 cores
Memory: 15.8 GB

mne: 0.23.0
numpy: 1.21.0 {blas=NO_ATLAS_INFO, lapack=lapack}
scipy: 1.6.3
matplotlib: 3.4.2 {backend=module://ipykernel.pylab.backend_inline}

sklearn: 0.24.2
numba: 0.53.1
nibabel: Not found
nilearn: Not found
dipy: Not found
cupy: Not found
pandas: 1.2.4
mayavi: Not found
pyvista: Not found
vtk: Not found

I am trying to plot sensors connectivity while I have the spectral connectivity parameters:

fmin, fmax = 4., 9.
sfreq = raw.info[‘sfreq’] # the sampling frequency
tmin = 0.0 # exclude the baseline period
epochs.load_data()
con, freqs, times, n_epochs, n_tapers = spectral_connectivity(
epochs, method=‘pli’, mode=‘multitaper’, sfreq=sfreq, fmin=fmin, fmax=fmax,
faverage=True, tmin=tmin, mt_adaptive=False, n_jobs=1)
plot_sensors_connectivity(epochs.info, connectivity[:, :, 0])

Hello @gharshini and welcome to the forum!

Getting 3D plotting to work properly can be quite tricky! We recommend strictly following our installation instructions to avoid issues.

Quoting from the instructions:

If you need MNE-Python’s 3D plotting capabilities (e.g., plotting estimated source activity on a cortical surface) it is a good idea to install MNE-Python into its own virtual environment. To do this with conda (this will create a conda environment called mne ):

$ curl --remote-name https://raw.githubusercontent.com/mne-tools/mne-python/master/environment.yml
$ conda env update --file environment.yml

https://mne.tools/stable/install/index.html

The curl command is typically not available on Windows; what you’ll need to do is download https://raw.githubusercontent.com/mne-tools/mne-python/master/environment.yml using your browser and then running the 2nd command mentioned above (conda env update ...)

Hope that helps!

Best wishes,

Richard

1 Like

Thank you for the welcome. It is a pleasure to be here and learn from the community!!! Thank you for a quick response too. Your suggestion worked for me after creating a new environment for MNE. Later I updated the version with the link provided by you.

Finally, I have a problem. While I get no error in importing pyvista/mayavi, I have a problem viewing the figure. It just simply displays as below:

<mne.viz.backends._pyvista._Figure at 0x226b4932d00>

How to view the figure?