diff --git a/packages/python/plotly/plotly/io/_base_renderers.py b/packages/python/plotly/plotly/io/_base_renderers.py index bbb5fabeb1..64760d4728 100644 --- a/packages/python/plotly/plotly/io/_base_renderers.py +++ b/packages/python/plotly/plotly/io/_base_renderers.py @@ -598,8 +598,8 @@ def to_mimebundle(self, fig_dict): return {"text/html": iframe_html} def build_filename(self): - ip = IPython.get_ipython() - cell_number = list(ip.history_manager.get_tail(1))[0][1] + 1 + ip = IPython.get_ipython() if IPython else None + cell_number = list(ip.history_manager.get_tail(1))[0][1] + 1 if ip else 0 filename = "{dirname}/figure_{cell_number}.html".format( dirname=self.html_directory, cell_number=cell_number )