_tkinter.TclError: couldn't connect to display ":1057.0"

It looks like the problem of pyplot (?) trying to connect to a display is back… this system doesn’t have a display, so any figure rendering needs be buffered. I don’t know how to fix… below the log:

Step 1) MELODIC
  - The existing/specified MELODIC directory will be used.
Step 2) Automatic classification of the components
  - registering the spatial maps to MNI
  - extracting the CSF & Edge fraction features
  - extracting the Maximum RP correlation feature
  - extracting the High-frequency content feature
  - classification
Found 1 file(s)
Found 27 head motion-related components in a total of 83 components.
Standard error:
Traceback (most recent call last):
  File "/data/EDB/MErest/code/ICA-AROMA-0.4.4-beta/ICA_AROMA.py", line 215, in 
    outDir)
  File "/gpfs/gsfs6/users/EDB/MErest/code/ICA-AROMA-0.4.4-beta/classification_plots.py", line 76, in classification_plot
    fig = plt.figure(figsize=[12, 4])
  File "/gpfs/gsfs6/users/EDB/MErest/code/env-hpc/lib/python3.6/site-packages/matplotlib/pyplot.py", line 525, in figure
    **kwargs)
  File "/gpfs/gsfs6/users/EDB/MErest/code/env-hpc/lib/python3.6/site-packages/matplotlib/backend_bases.py", line 3218, in new_figure_manager
    return cls.new_figure_manager_given_figure(num, fig)
  File "/gpfs/gsfs6/users/EDB/MErest/code/env-hpc/lib/python3.6/site-packages/matplotlib/backends/_backend_tk.py", line 1008, in new_figure_manager_given_figure
    window = Tk.Tk(className="matplotlib")
  File "/usr/local/Anaconda/envs/py3.6/lib/python3.6/tkinter/__init__.py", line 2020, in __init__
    self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
_tkinter.TclError: couldn't connect to display ":1057.0"
Return code: 1

PS: This is fmriprep 1.2.6-1. Can’t update to the latest because of the git-annex issue discussed in the other thread.

Unfortunately, we cannot disable the execution of that function trying to plot (after all, fMRIPrep will discard such a plot) - https://github.com/maartenmennes/ICA-AROMA/blob/a629eb70e7fe6669d65761bd543b8186af6c21a9/ICA_AROMA.py#L225

Given your settings, I think it is safe to change your matplotlib backend to Agg system-wise. To do so, this one-liner searches for the config file and modifies the setting:

sed -i 's/\(backend *: \).*$/\1Agg/g' $( python -c "import matplotlib; print(matplotlib.matplotlib_fname())" )

It is highly possible that you will also need to make sure you have Xvfb installed. Nipype uses it to open a virtual framebuffer in headless scenarios (like yours). Finally, make sure you don’t have a DISPLAY environment variable set.

An alternative way around this problem, if you happen to have a functional vnc server running on your compute nodes, is to point the DISPLAY to the vnc server.

Finally, and considering that the ICA-AROMA code is quite experimental, you may go around this splitting it from fMRIPrep (i.e. run fMRIPrep without it and then running ICA-AROMA on more controllable settings: there are a bunch of moving pieces here).

Hi @winkler, were you able to run ICA-AROMA using xvfb or by modifying matplotlib configuration?

Yes! After changing the backend to Agg it worked.
Many thanks!

2 Likes