Installing mne-icalabel changes eeg plot window

Installing mne-icalabel changes the way eeg.plot() displays.
Is there a way to change it back without uninstalling mne-icalabel?
Thanks,
John

mne==1.3.1
mne-icalabel==0.4
matplotlib 3.7.1
mne-qt-browser==0.5.0
PyQt5==5.15.9
PyQt5-Qt5==5.15.2
PyQt5-sip==12.11.1
pyqtgraph==0.13.3
QtPy==2.3.1
sphinxcontrib-qthelp==1.0.3
Linux pop-os 6.2.6-76060206-generic #202303130630~1679424972~22.04~4a8cde1 SMP PREEMPT_DYNAMIC Tue M x86_64 x86_64 x86_64 GNU/Linux

Before installing mne-icalabel:

After installing mne-icalabel:

It seems like something changed the plotting backend from matplotlib to qt. You can change it back with mne.viz.set_browser_backend("matplotlib").

For clarification, there are 2 backends to plot continuous data: matplotlib and qt, with the second being newer and faster. In your setup, you did not have mne-qt-browser (a.k.a the qt backend installed) and when you installed mne-icalabel, it likely also installed mne-qt-browser, one of its optional dependencies (under the all or gui key).

Thus, the next time you plotted continuous data with mne, it detected that mne-qt-browser was now installed and switched to the newer backend.

Mathieu

2 Likes

Thanks for the replies @cbrnr and @mscheltienne !

I had been using the magic %matplotlib qt so that the plots would open in an interactive window.
It looks like @mscheltienne assessment about mne-qt-browser is correct, as it wasn’t installed before installing mne-icalabel.
So I guess my recourse is to uninstall mne-qt-browser?

In related news, there’s something weird going on with qt, mne browse --raw and/or mnelab:

It looks like I’ve entered the Ninth Circle of Dante’s Python Dependency Inferno.

x pip install "mnelab[full]"
Collecting mnelab[full]
  Using cached mnelab-0.8.6-py3-none-any.whl (91 kB)
Requirement already satisfied: scipy>=1.7.0 in /home/john/anaconda3/envs/neurogram/lib/python3.10/site-packages (from mnelab[full]) (1.10.1)
Requirement already satisfied: pyxdf>=1.16.0 in /home/john/anaconda3/envs/neurogram/lib/python3.10/site-packages (from mnelab[full]) (1.16.4)
Requirement already satisfied: matplotlib>=3.6.2 in /home/john/anaconda3/envs/neurogram/lib/python3.10/site-packages (from mnelab[full]) (3.7.1)
Requirement already satisfied: PySide6>=6.4.2 in /home/john/anaconda3/envs/neurogram/lib/python3.10/site-packages (from mnelab[full]) (6.5.0)
Requirement already satisfied: mne>=1.2.0 in /home/john/anaconda3/envs/neurogram/lib/python3.10/site-packages (from mnelab[full]) (1.3.1)
Requirement already satisfied: numpy>=1.20.0 in /home/john/anaconda3/envs/neurogram/lib/python3.10/site-packages (from mnelab[full]) (1.23.5)
Requirement already satisfied: pyEDFlib>=0.1.22 in /home/john/anaconda3/envs/neurogram/lib/python3.10/site-packages (from mnelab[full]) (0.1.32)
Requirement already satisfied: scikit-learn>=1.0.0 in /home/john/anaconda3/envs/neurogram/lib/python3.10/site-packages (from mnelab[full]) (1.2.2)
Requirement already satisfied: python-picard>=0.7.0 in /home/john/anaconda3/envs/neurogram/lib/python3.10/site-packages (from mnelab[full]) (0.7)
Requirement already satisfied: pybv>=0.7.4 in /home/john/anaconda3/envs/neurogram/lib/python3.10/site-packages (from mnelab[full]) (0.7.5)
Requirement already satisfied: pyparsing>=2.3.1 in /home/john/anaconda3/envs/neurogram/lib/python3.10/site-packages (from matplotlib>=3.6.2->mnelab[full]) (3.0.9)
Requirement already satisfied: pillow>=6.2.0 in /home/john/anaconda3/envs/neurogram/lib/python3.10/site-packages (from matplotlib>=3.6.2->mnelab[full]) (9.5.0)
Requirement already satisfied: kiwisolver>=1.0.1 in /home/john/anaconda3/envs/neurogram/lib/python3.10/site-packages (from matplotlib>=3.6.2->mnelab[full]) (1.4.4)
Requirement already satisfied: cycler>=0.10 in /home/john/anaconda3/envs/neurogram/lib/python3.10/site-packages (from matplotlib>=3.6.2->mnelab[full]) (0.11.0)
Requirement already satisfied: python-dateutil>=2.7 in /home/john/anaconda3/envs/neurogram/lib/python3.10/site-packages (from matplotlib>=3.6.2->mnelab[full]) (2.8.2)
Requirement already satisfied: packaging>=20.0 in /home/john/anaconda3/envs/neurogram/lib/python3.10/site-packages (from matplotlib>=3.6.2->mnelab[full]) (23.0)
Requirement already satisfied: contourpy>=1.0.1 in /home/john/anaconda3/envs/neurogram/lib/python3.10/site-packages (from matplotlib>=3.6.2->mnelab[full]) (1.0.7)
Requirement already satisfied: fonttools>=4.22.0 in /home/john/anaconda3/envs/neurogram/lib/python3.10/site-packages (from matplotlib>=3.6.2->mnelab[full]) (4.39.3)
Requirement already satisfied: jinja2 in /home/john/anaconda3/envs/neurogram/lib/python3.10/site-packages (from mne>=1.2.0->mnelab[full]) (3.1.2)
Requirement already satisfied: pooch>=1.5 in /home/john/anaconda3/envs/neurogram/lib/python3.10/site-packages (from mne>=1.2.0->mnelab[full]) (1.7.0)
Requirement already satisfied: decorator in /home/john/anaconda3/envs/neurogram/lib/python3.10/site-packages (from mne>=1.2.0->mnelab[full]) (5.1.1)
Requirement already satisfied: tqdm in /home/john/anaconda3/envs/neurogram/lib/python3.10/site-packages (from mne>=1.2.0->mnelab[full]) (4.65.0)
Requirement already satisfied: PySide6-Essentials==6.5.0 in /home/john/anaconda3/envs/neurogram/lib/python3.10/site-packages (from PySide6>=6.4.2->mnelab[full]) (6.5.0)
Requirement already satisfied: shiboken6==6.5.0 in /home/john/anaconda3/envs/neurogram/lib/python3.10/site-packages (from PySide6>=6.4.2->mnelab[full]) (6.5.0)
Requirement already satisfied: PySide6-Addons==6.5.0 in /home/john/anaconda3/envs/neurogram/lib/python3.10/site-packages (from PySide6>=6.4.2->mnelab[full]) (6.5.0)
Requirement already satisfied: numexpr in /home/john/anaconda3/envs/neurogram/lib/python3.10/site-packages (from python-picard>=0.7.0->mnelab[full]) (2.8.4)
Requirement already satisfied: threadpoolctl>=2.0.0 in /home/john/anaconda3/envs/neurogram/lib/python3.10/site-packages (from scikit-learn>=1.0.0->mnelab[full]) (3.1.0)
Requirement already satisfied: joblib>=1.1.1 in /home/john/anaconda3/envs/neurogram/lib/python3.10/site-packages (from scikit-learn>=1.0.0->mnelab[full]) (1.2.0)
Requirement already satisfied: requests>=2.19.0 in /home/john/anaconda3/envs/neurogram/lib/python3.10/site-packages (from pooch>=1.5->mne>=1.2.0->mnelab[full]) (2.28.2)
Requirement already satisfied: platformdirs>=2.5.0 in /home/john/anaconda3/envs/neurogram/lib/python3.10/site-packages (from pooch>=1.5->mne>=1.2.0->mnelab[full]) (3.2.0)
Requirement already satisfied: six>=1.5 in /home/john/anaconda3/envs/neurogram/lib/python3.10/site-packages (from python-dateutil>=2.7->matplotlib>=3.6.2->mnelab[full]) (1.16.0)
Requirement already satisfied: MarkupSafe>=2.0 in /home/john/anaconda3/envs/neurogram/lib/python3.10/site-packages (from jinja2->mne>=1.2.0->mnelab[full]) (2.1.2)
Requirement already satisfied: urllib3<1.27,>=1.21.1 in /home/john/anaconda3/envs/neurogram/lib/python3.10/site-packages (from requests>=2.19.0->pooch>=1.5->mne>=1.2.0->mnelab[full]) (1.26.15)
Requirement already satisfied: charset-normalizer<4,>=2 in /home/john/anaconda3/envs/neurogram/lib/python3.10/site-packages (from requests>=2.19.0->pooch>=1.5->mne>=1.2.0->mnelab[full]) (3.1.0)
Requirement already satisfied: idna<4,>=2.5 in /home/john/anaconda3/envs/neurogram/lib/python3.10/site-packages (from requests>=2.19.0->pooch>=1.5->mne>=1.2.0->mnelab[full]) (3.4)
Requirement already satisfied: certifi>=2017.4.17 in /home/john/anaconda3/envs/neurogram/lib/python3.10/site-packages (from requests>=2.19.0->pooch>=1.5->mne>=1.2.0->mnelab[full]) (2022.12.7)
Installing collected packages: mnelab
Successfully installed mnelab-0.8.6

dev on git multiclass [$] via conda neurogram 
> mnelab
qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "" even though it was found.
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.

Available platform plugins are: eglfs, linuxfb, minimal, minimalegl, offscreen, vkkhrdisplay, vnc, wayland-egl, wayland, xcb.

zsh: IOT instruction (core dumped)  mnelab

dev on git multiclass [$] via conda neurogram 
x pip freeze | rg -i qt
mne-qt-browser==0.5.0
PyQt5==5.15.9
PyQt5-Qt5==5.15.2
PyQt5-sip==12.11.1
pyqtgraph==0.13.3
QtPy==2.3.1
sphinxcontrib-qthelp==1.0.3

Installed libxcb-cursor0 and have a new issue. From mnelab when I try to plot:

Traceback (most recent call last):
  File "/home/john/anaconda3/envs/neurogram/lib/python3.10/site-packages/mnelab/mainwindow.py", line 783, in plot_data
    win = fig.canvas.manager.window
AttributeError: 'MNEQtBrowser' object has no attribute 'canvas'

In my experience, mixing pip and conda is always asking for trouble, especially with such large packages like PySide6. I would try to install all dependencies with conda (they should be available in conda-forge I think), and then pip install --no-dependencies mnelab. Or maybe there is already a working conda package for MNELAB? @richard?

No, I believe there was still an open issue upstream at PySide6. A missing feature related to the event loop.

1 Like

I believe I may have been mistaken here – MNELAB 0.8.6 is available from conda-forge…

Nice! Then @JohnAtl please use conda to install everything.

Conda can take ages to resolve an environment (if ever). Mamba flaked out on me. Haven’t tried Poetry yet.
I read somewhere that a good way to manage environments is to create them with conda, then use pip exclusively.
Edit: Here on the Anaconda site

To wit; first 1:45 conda was just hung, the other 3 minutes it was calculatin’.

Yes, conda is very often unusable, but mamba has worked nicely for me. However, I don’t use conda/mamba as my daily driver at all. I prefer pip in combination with venv. So far, I’ve never had any unsolvable problems, and it is also the official packaging tool for Python.

That article is rather old, so a lot has probably changed. But yeah, the take home message is to never mix conda and pip.

1 Like

Thanks.
I’m going to give venv a try.

Recreated my environment (inc. mnelab 0.8.6) in a venv.
Any suggestions?
mne browse_raw still works, though uses the dark theme, and shows the error below.

MNELAB

> mnelab
qt.dbus.integration: Could not connect "org.freedesktop.IBus" to globalEngineChanged(QString)
Opening raw data file /home/john/Projects/Neurogram/Epilepsy/dev/data/test_eegs/FA0753MF_combined_ann_raw.fif...
    Read a total of 1 projection items:
        Average EEG reference (1 x 19) active
    Range : 0 ... 239999 =      0.000 ...  1199.995 secs
Ready.
Reading 0 ... 239999  =      0.000 ...  1199.995 secs...
Using qt as 2D backend.
Traceback (most recent call last):
  File "/home/john/.local/envs/neurogram/lib/python3.10/site-packages/mnelab/mainwindow.py", line 783, in plot_data
    win = fig.canvas.manager.window
AttributeError: 'MNEQtBrowser' object has no attribute 'canvas'


# Command History

from copy import deepcopy
import mne
from mnelab.io import read_raw

datasets = []
data = read_raw("/home/john/Projects/Neurogram/Epilepsy/dev/data/test_eegs/FA0753MF_combined_ann_raw.fif", preload=True)
datasets.insert(0, data)
data.plot(events=events, n_channels=19)

MNE browse_raw

x MNE_BROWSER_THEME="light" mne browse_raw --raw data/test_eegs/FA0750X2_combined_ann_raw.fif
Opening raw data file data/test_eegs/FA0750X2_combined_ann_raw.fif...
    Read a total of 1 projection items:
        Average EEG reference (1 x 19) active
    Range : 0 ... 254799 =      0.000 ...  1273.995 secs
Ready.
Using qt as 2D backend.
qt.dbus.integration: Could not connect "org.freedesktop.IBus" to globalEngineChanged(QString)
/home/john/.local/envs/neurogram/bin/mne:8: RuntimeWarning: Setting theme='light' is not yet supported for PySide6 in qdarkstyle, it will be ignored
  sys.exit(main())
Channels marked as bad:
none

You should create an entirely new environment and not install into an existing environment. Dependency resolution should work then. You may have to be patient though.

It might be that MNELAB and MNE Qt Browser do not play well together. I haven’t tested this combination, because I’m using the Matplotlib-based backend. You might have to set the backend in your MNE configuration, e.g.

import mne
mne.set_config("MNE_BROWSER_BACKEND", "matplotlib")

With this change, both MNELAB and mne browse_raw should use the Matplotlib backend (and therefore work and use the specified light theme).

I think you’re right.
I installed mne_qt_browser (don’t recall why), and it went to the dark theme with the giant time window at the bottom. Also, mnelab started complaining that (as I recall) there was no canvas available. I uninstalled mne_qt_browser, and things went back to normal.
Thanks!

And thanks everyone for suggestions!

(BTW, using venv, and so far so good. It seems more baremetal than all the conda shenanigans.)