Thanks to visit codestin.com
Credit goes to github.com

Skip to content

'MPLBACKEND=webagg' is overwritten by agg when $DISPLAY is not set on Linux #14903

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
GreenCourt opened this issue Jul 28, 2019 · 6 comments · Fixed by #15512
Closed

'MPLBACKEND=webagg' is overwritten by agg when $DISPLAY is not set on Linux #14903

GreenCourt opened this issue Jul 28, 2019 · 6 comments · Fixed by #15512
Assignees
Labels
Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. status: confirmed bug
Milestone

Comments

@GreenCourt
Copy link

Bug report

  • The environment variable MPLBACKEND=webagg is overwritten by 'agg' when $DISPLAY is not set on Linux.
  • The behavior of backend:webagg written in matplotlibrc was as same as MPLBACKEND=webagg (I tried).
  • I want to avoid hard-coding the backend to .py file, because I use the same code on other environment.

Code for reproduction

# matplotlibrc
webagg.open_in_browser : False
webagg.address : 0.0.0.0
# test.py
import matplotlib.pyplot as plt
print(plt.get_backend())

Actual outcome

When I type the shell command MPLBACKEND=WebAgg DISPLAY= python test.py,

agg

the backend is overwritten by agg.

When I type the shell command MPLBACKEND=WebAgg DISPLAY=:0 python test.py (although X11 is not installed),

WebAgg

I can use webagg.

Expected outcome

When I type the shell command MPLBACKEND=WebAgg DISPLAY= python test.py,

WebAgg
  • I want to use webagg even when X11 is not installed.
  • I want to use the environment variable MPLBACKEND to avoid hard-coding the backend.

Question

Does matplotlib overwrite the backend by 'agg', when $DISPLAY is empty?
I understand that the fallback behavior is useful.
However, is there any reason that webagg must be fallbacked to agg?

Or, is there a correct way (not setting the $DISPLAY) to avoid the fallback behavior?

Matplotlib version

  • Operating system: Debian 10
  • Matplotlib version: 3.1.0
  • Python version: 3.7.3 (anaconda)
@tacaswell tacaswell added this to the v3.1.2 milestone Jul 28, 2019
@tacaswell
Copy link
Member

That is definitely a bug in the fallback logic to make sure we don't try to use a GUI backend on a headless server. I suspect we have miss-categorized webagg as a GUI backend.

@tacaswell tacaswell added the Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. label Aug 13, 2019
@GreenCourt
Copy link
Author

Thanks for your reply!
Also, if webagg.open_in_browser is automatically set to False when $DISPLAY is not set,
I think it is very convenient.

@anntzer
Copy link
Contributor

anntzer commented Aug 27, 2019

The short term fix is to add webagg to https://github.com/matplotlib/matplotlib/blob/master/lib/matplotlib/rcsetup.py#L44. The long term fix is... we need to figure out what rcParams["backend_fallback"] really means. I have a PR that fixes that, but runs into other inconsistencies :(

@GreenCourt
Copy link
Author

Is the fallback behavior really needed even when users explicitly set the backend by MPLBACKEND or matplotlibrc?

@anntzer
Copy link
Contributor

anntzer commented Sep 13, 2019

this was requested many times when the fallback was not present (you can search the issue tracker), so heh.

@tacaswell tacaswell self-assigned this Oct 22, 2019
tacaswell added a commit to tacaswell/matplotlib that referenced this issue Oct 25, 2019
There is logic in pyplot to determine if the user has is some way
selected a backend which is incompatible with the interactive
framework that we detect is running.  This helps prevent issues where
the user is already using one GUI frame work (ex tk) before Matplotlib
is imported and has Matplotlib configured to use Qt.  The other place
this behavior is desired is if Matplotlib is configured to use a GUI
framework by default, but is then imported on a headless server.  By
detecting there is no DISPLAY we fall back to Agg rather than failing
to import.

From the point of view of having UI events, webagg and nbagg are
interactive backends, however from the point of view of requiring
DISPLAY they are not.

This is the minimal fix, filtering out these two backends in pyplot
rather than changing this in rcsetup, incase anyone is relying on
those lists for other purposes.

closes matplotlib#14903
tacaswell added a commit to tacaswell/matplotlib that referenced this issue Oct 25, 2019
There is logic in pyplot to determine if the user has is some way
selected a backend which is incompatible with the interactive
framework that we detect is running.  This helps prevent issues where
the user is already using one GUI frame work (ex tk) before Matplotlib
is imported and has Matplotlib configured to use Qt.  The other place
this behavior is desired is if Matplotlib is configured to use a GUI
framework by default, but is then imported on a headless server.  By
detecting there is no DISPLAY we fall back to Agg rather than failing
to import.

From the point of view of having UI events, webagg and nbagg are
interactive backends, however from the point of view of requiring
DISPLAY they are not.

This is the minimal fix, filtering out these two backends in pyplot
rather than changing this in rcsetup, incase anyone is relying on
those lists for other purposes.

closes matplotlib#14903
tacaswell added a commit to tacaswell/matplotlib that referenced this issue Oct 31, 2019
There is logic in pyplot to determine if the user has is some way
selected a backend which is incompatible with the interactive
framework that we detect is running.  This helps prevent issues where
the user is already using one GUI frame work (ex tk) before Matplotlib
is imported and has Matplotlib configured to use Qt.  The other place
this behavior is desired is if Matplotlib is configured to use a GUI
framework by default, but is then imported on a headless server.  By
detecting there is no DISPLAY we fall back to Agg rather than failing
to import.

From the point of view of having UI events, webagg and nbagg are
interactive backends, however from the point of view of requiring
DISPLAY they are not.

This is the minimal fix, filtering out these two backends in pyplot
rather than changing this in rcsetup, incase anyone is relying on
those lists for other purposes.

closes matplotlib#14903
@GreenCourt
Copy link
Author

Thanks for your work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. status: confirmed bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants