Adding 3D plots to MNE Report on headless Linux server (RuntimeError: Cannot connect to a valid display)

Dear MNE community,

I’m trying to generate a report with 3D coregistration plots using mne.Report on a headless Linux server (no display).

Today, I freshly reinstalled MNE Python including the offscreen rendering setup with:

conda install -c conda-forge "vtk>=9.2=*osmesa*" "mesalib=21.2.5"

The output of mne.sys_info() includes:

- Platform: Linux-5.14.0-503.22.1.el9_5.x86_64-x86_64-with-glibc2.34
- Python: 3.11.6
- mne: 1.9.0
- pyvista: 0.45.0 (OpenGL 3.3 (Core Profile) Mesa 21.2.5 via softpipe)
- pyvistaqt: 0.11.2
- vtk: 9.2.6
- qtpy: 2.4.3

I attempt to add a coregistration plot like this:

report.add_trans(
    trans=estim_trans,
    info=raw.info,
    title=f"Coregistration ({Tx}): {subject}",
    subject=subject,
    subjects_dir=fs_subjects_dir,
    replace=True
)

However, this fails with the error:

RuntimeError: Cannot connect to a valid display

My goal
I want to add 3D plots to the report without using any GUI or X11 (e.g., using MESA + OSMesa).

Question
Is there a known working setup for e.g. report.add_trans() with offscreen rendering using MESA?

Thanks in advance for any suggestions!
All the best,
Till

Hello, have you tried to run the script with xvfb-run python …?

Best wishes,
Richard

1 Like

Hello Richard,

Thank you for the prompt reply. Yes, using xvfb-run python does work indeed. Unfortunately, it takes quite a while to run, so I’d prefer to avoid it if possible.

Best regards,
Till

Hello, I don’t know how you could avoid this, sorry!

Okay, thanks for letting me know! :slight_smile: