Skip to content

Commit

Permalink
fix: if matplotlib was imported before solara, we set the backend
Browse files Browse the repository at this point in the history
Normally, setting MPLBACKEND will set the backend because importing
matplotlib will set the backend based on this environment variable.
However, in the case where matplotlib is imported before solara,
such as jdaviz is doing, we need to set the backend manually.

Related: spacetelescope/jdaviz#2909
  • Loading branch information
maartenbreddels committed Aug 20, 2024
1 parent b53b551 commit c4fd7d6
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions solara/server/patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,12 @@ def patch():
os.environ["MPLBACKEND"] = "module://ipykernel.pylab.backend_inline"
else:
os.environ["MPLBACKEND"] = "module://matplotlib_inline.backend_inline"
# if matplotlib is already imported, we need to set the backend
# similar to how matplotlib does it in it's __init__.py
if "matplotlib" in sys.modules:
import matplotlib

matplotlib.rcParams["backend"] = os.environ.get("MPLBACKEND")

# the ipyvue.Template module cannot be accessed like ipyvue.Template
# because the import in ipvue overrides it
Expand Down

0 comments on commit c4fd7d6

Please sign in to comment.