Warnings and error messages when using mne-qt-browser

  • MNE-Python version: 0.24
  • operating system: Mac OS 11.3.1

I just updated to .24 and love the new data browser. I have a question about a warning message I’m receiving along with an error message when using the browser with tkinter.

Following the simple example at GitHub - mne-tools/mne-qt-browser: A new backend for the 2D data browser in MNE-Python, I started with

import mne
mne.viz.set_browser_backend("pyqtgraph")
raw = mne.io.read_raw_edf('myfile.edf',preload=True)
raw.plot(block=True,duration=40,start=10)

The data browser appears and works fine, but I also receive a warning message:

    RuntimeWarning: PyOpenGL was not found and OpenGL can't be used!
    Consider installing pyopengl with "pip install pyopengl".

I then installed pyopengl and ran the code again, only to obtain an extremely long error message ending with the following:

ImportError: ('Unable to load OpenGL library', 'dlopen(OpenGL, 10): image not found', 'OpenGL', None)

I then uninstalled pyopengl just so I could at least get things to work.

Question 1: I don’t really understand the roles of OpenGL and PyOpenGL and whether I should be concerned about this warning and, if I should be, how I can go about resolving it.

My second question focuses on embedding raw plots on figure tkinter figure canvases. With the previous raw.plot(), I used the following syntax to do this:

import mne
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
import matplotlib.backends.backend_tkagg as tkagg
from tkinter import Tk, Frame,TOP,BOTTOM

root = Tk()
root.wm_title("Main Window")
root.geometry('1500x1000')

raw = mne.io.read_raw_edf('myfile.edf',preload=True)

fig=raw.plot(block=True,duration=40,start=10)
canvas_frame=Frame(root,height = 1500,width = 1000)
canvas_frame.pack(side=TOP,expand=True)
canvas = FigureCanvasTkAgg(fig, master=canvas_frame)
canvas.draw()
canvas.get_tk_widget().pack(side=TOP,fill=BOTH,expand=1)

root.mainloop()

This has worked very well for me. However, when I insert mne.viz.set_browser_backend("pyqtgraph") so as to place the updated browser on the canvas, I receive the same warning as above, along with a lengthy error message ending with

AttributeError: ‘PyQtGraphBrowser’ object has no attribute ‘set_canvas’

Question 2: Is this error related to the above warning and/or is there some other explanation?

I realize mne-qt-browser is a new feature, so please let me know if I should post these questions on its associated github page instead.

Update: I’ve been able to resolve the first issue, which appears to be specific to my Mac Big Sur OS. A description of the problem and a simple solution are outlined at Unable to import opengl.gl in python on macos - Stack Overflow

With regard to placing the mne-qt-browser plot on a canvas, the error message,

AttributeError: ‘PyQtGraphBrowser’ object has no attribute ‘set_canvas’

still results, but only when I close the figure.

I don’t have the necessary experience with Tk or Qt to tell you the answer, but a quick google search for embed qt in tk turns up a couple promising-looking pages:

Hello Paul,

thank you for your hint to the solution of the OpenGl-Problem on MacOs. It is good to know that there can be issues with OpenGL and Big Sur.

Martin

@PaulF Which version of Python are you using? Could you please share the output of

import mne
mne.sys_info()

Thanks!

Yes–here it is:

Platform: macOS-10.16-x86_64-i386-64bit
Python: 3.9.2 (v3.9.2:1a79785e3e, Feb 19 2021, 09:06:10) [Clang 6.0 (clang-600.0.57)]
Executable: /Library/Frameworks/Python.framework/Versions/3.9/bin/python3.9
CPU: i386: 8 cores
Memory: 32.0 GB

mne: 0.24.0
numpy: 1.21.3 {blas=openblas, lapack=openblas}
scipy: 1.7.1
matplotlib: 3.4.2 {backend=MacOSX}

sklearn: 0.24.1
numba: Not found
nibabel: Not found
nilearn: Not found
dipy: Not found
cupy: Not found
pandas: 1.2.4
mayavi: Not found
pyvista: Not found
pyvistaqt: Not found
ipyvtklink: Not found
vtk: Not found
PyQt5: 5.15.6
ipympl: Not found
mne_qt_browser: 0.1.6

There is a problem with macOS Big sure that moved some standard library elsewhere, and the paths are invalid when using ‘old’ python version. For instance, I run python 3.8.10 and I ran into this problem with multiple third-parties libraries already.

Don’t quote me on that, but I think it was solved in Python 3.9.3. So if you upgrade to a more recent 3.9 version, you should not need to patch this with '/System/Library/Frameworks/OpenGL.framework/OpenGL'.

Yep, this fix def. made it into Python 3.9 and was also backported to 3.8.

Indeed! Fix in 3.9.7 (I knew I shouldn’t be quoted on 3.9.3 :stuck_out_tongue:) and backported to 3.8.12.

What about upgrading to 3.10? I just tried this but received the following error when trying to import mne:

import mne
Traceback (most recent call last):
File “<pyshell#8>”, line 1, in
import mne
File “/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/mne/init.py”, line 22, in
from .utils import (set_log_level, set_log_file, verbose, set_config,
File “/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/mne/utils/init.py”, line 9, in
from .check import (check_fname, check_version, check_random_state,
File “/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/mne/utils/check.py”, line 21, in
from …fixes import _median_complex
File “/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/mne/fixes.py”, line 360, in
‘preserves_dtype’: [np.float64],
AttributeError: module ‘numpy’ has no attribute ‘float64’

My version of numpy is up to date. (1.21.4).

Perhaps I should go back, uninstall 3.10, and install 3.9.7?

Python 3.10 is a bit too recent to my liking (minor version 0!), and you will probably encounter a lot of bugs like this one. I would suggest using the latest 3.9 version instead, 3.9.8.

1 Like

@PaulF
Concerning your original questions:

Question 1

We found that OpenGL only enhances performance for some hardware-configurations. Since it also turned out to cause additional problems as in your case, the new default for use_opengl is now False. To avoid the warning, you can now manually set use_opengl to False, this won’t be necessary anymore with version 0.24.1 of MNE-Python.

Question 2

I tried to find a solution for your problem, but unfortunately it seems that PyQt and tkinter aren’t compatible.
What raw.plot() returns is an instance of QWidget (or more specific a subclass, QMainWindow) which can be integrated into PyQt-Applications.
The FigureCanvasTkAgg-Class you use wraps instances of matplotlib.figure.Figure to be used with tkinter.

I would be glad to help you if you got questions about integrating PyQtBrowser into a PyQt-Application. Otherwise you need to continue using matplotlib for your tkinter-application.

3 Likes

Thanks Martin for looking into this. I very much appreciate it. Given all the matplotlib tools I’ve integrated into my tkinter app at this point, I think I’ll just stick with what I’m doing. In hindsight perhaps I should have utilized PyQt since the start so I could integrate your beautiful data browser into what I’m doing.

Thanks again.

Paul

1 Like