mne.viz.plot_alignment on HPC Docker

I’m trying to run mne.viz.plot_alignment on the official Docker image for Python with the required packages. I get the following error:

Cannot connect to a valid display. I’ve included some of the error logs below. I’ve tried to set certain variables but to no avail. Is it possible to run this in a headless mode?

I’ve tried to add the following to my .sh file.

export DISPLAY=:99.0

export PYVISTA_OFF_SCREEN=true

export PYVISTA_USE_IPYVTK=true


Traceback (most recent call last):
File “/script.py”, line 274, in
fig = mne.viz.plot_alignment(raw.info,meg=‘helmet’,dig=True,show_axes=True,coord_frame=‘meg’)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “”, line 12, in plot_alignment
File “/usr/local/lib/python3.12/site-packages/mne/viz/_3d.py”, line 819, in plot_alignment
renderer = _get_renderer(
^^^^^^^^^^^^^^
File “/usr/local/lib/python3.12/site-packages/mne/viz/backends/renderer.py”, line 57, in _get_renderer
return backend._Renderer(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/usr/local/lib/python3.12/site-packages/mne/viz/backends/_utils.py”, line 434, in func
meth(self, *args, **kwargs)
File “/usr/local/lib/python3.12/site-packages/mne/viz/backends/_qt.py”, line 1778, in init
super().init(*args, **kwargs)
File “/usr/local/lib/python3.12/site-packages/mne/viz/backends/_pyvista.py”, line 269, in init
self.plotter = self.figure._build()
^^^^^^^^^^^^^^^^^^^^
File “/usr/local/lib/python3.12/site-packages/mne/viz/backends/_pyvista.py”, line 153, in _build
out = _init_mne_qtapp(enable_icon=True, splash=self.splash)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/usr/local/lib/python3.12/site-packages/mne/viz/backends/_utils.py”, line 161, in _init_mne_qtapp
raise RuntimeError(“Cannot connect to a valid display”)

1 Like

It appears my understanding of the scenario was incorrect. The original use case was to allow for an actual preview of the data collected to verify accuracy. On the HPC this will not be required so the mne.viz.plot_alignment is not necessary.

I am running into the same issue. I want to create an mne.Report that contains a co-registration section via report.add_trans, which makes use of mne.viz.plot_slignment.

It seems like a display is needed to produce plots from mne.viz.plot_alignment :thinking:

Does anyone know of a way around this?