The easiest way to demonstrate is using sct_dmri_display_bvecs:
--
Spinal Cord Toolbox (git-master-a62fb672c602b9863a8c03521eb272bfd7bad9e1)
sct_dmri_display_bvecs -bvec sct_example_data/dmri/bvecs.txt
--
Saving figure: bvecs.png
/home/joshua/repos/spinalcordtoolbox/spinalcordtoolbox/scripts/sct_dmri_display_bvecs.py:137: UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure.
plt.show()
This warning occurs and no figure is shown.
We explicitly set the backend type using the MPLBACKEND environment variable. (Option 2. in this list.)
We started using the Agg backend in #2157 (https://github.com/spinalcordtoolbox/spinalcordtoolbox/pull/2238/commits/cd521dbdce9fb74332528a6a0d3b253012dfd492) to avoid crashes on headless systems (see https://github.com/spinalcordtoolbox/spinalcordtoolbox/issues/2138).
Moving forward, I can think of two options, depending on whether we need interactive matplotlib windows in SCT.
MPLBACKEND=Agg (a non-interactive backend) for headless systems only. plt.show().Thank you for opening this @joshuacwnewton
In the case of sct_dmri_display_bvecs I we _can_ go without interactive figure, and having it work would be like the cherry on the cake. Maybe we can check if user is on headless system, and if that's the case interactive mode is turned off?
Maybe we can check if user is on headless system, and if that's the case interactive mode is turned off?
The interesting thing is, I think we already do check if the user is on a headless system... but in the launcher:
So we're setting the same environment variable twice: once in the launcher, and once in the user's RC file (via the installer), which seems redundant. It's possible that this was accidental, and that just the check in the launcher will be sufficient (as you've suggested).
We explicitly set the backend type using the
MPLBACKENDenvironment variable. (Option 2. in this list.)
Interesting, there is missing elif statement for zsh. Is that the intention?
EDIT - Sorry, I have not noticed, that it is due to:
BTW.
I thought that export MPLBACKEND=TkAgg run in my zsh CLI could solve the issue with plt.show(), so I tried:
git checkout master
export MPLBACKEND=TkAgg
sct_dmri_display_bvecs -bvec ~/sub-001/dwi/sub-001_dwi.bvec
But it didn't and I still get the same warning:
UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure.
plt.show()