Skip to content

Commit 48dc35f

Browse files
authored
experimental init: Fix Solara import by making it lazy (#2357)
In the experimental `__init__.py`, it always tries to import the "old" solara_viz module, even if it's not needed because only the cell space is used. This PR wraps that in a try block to also allow using the experimental cell space without Solara installed.
1 parent e255a2d commit 48dc35f

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

mesa/experimental/__init__.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
from mesa.experimental import cell_space
44

5-
from .solara_viz import JupyterViz, Slider, SolaraViz, make_text
5+
try:
6+
from .solara_viz import JupyterViz, Slider, SolaraViz, make_text
67

7-
__all__ = ["cell_space", "JupyterViz", "SolaraViz", "make_text", "Slider"]
8+
__all__ = ["cell_space", "JupyterViz", "Slider", "SolaraViz", "make_text"]
9+
except ImportError:
10+
print(
11+
"Could not import SolaraViz. If you need it, install with 'pip install --pre mesa[viz]'"
12+
)
13+
__all__ = ["cell_space"]

0 commit comments

Comments
 (0)