Skip to content

Commit bee13cd

Browse files
committed
Update jupyter version warnings to import jupyterlab later
1 parent 22d90c4 commit bee13cd

File tree

1 file changed

+21
-15
lines changed

1 file changed

+21
-15
lines changed

packages/python/plotly/plotly/io/_utils.py

+21-15
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,30 @@
66
import warnings
77
import psutil
88

9-
jupyter_notebook = optional_imports.get_module("notebook")
10-
jupyter_lab = optional_imports.get_module("jupyterlab")
11-
129

1310
def display_jupyter_version_warnings():
11+
parent_process = None
12+
try:
13+
parent_process = psutil.Process().parent().cmdline()[-1]
14+
except Exception:
15+
pass
1416

15-
parent_process = psutil.Process().parent().cmdline()[-1]
16-
17-
if "jupyter-notebook" in parent_process and jupyter_notebook.__version__ < "7":
18-
# Add warning about upgrading notebook
19-
warnings.warn(
20-
f"Plotly version >= 6 requires Jupyter Notebook >= 7 but you have {jupyter_notebook.__version__} installed.\n To upgrade Jupyter Notebook, please run `pip install notebook --upgrade`."
21-
)
22-
elif "jupyter-lab" in parent_process and jupyter_lab.__version__ < "3":
23-
# Add warning about upgrading jupyterlab
24-
warnings.warn(
25-
f"Plotly version >= 6 requires JupyterLab >= 3 but you have {jupyter_lab.__version__} installed. To upgrade JupyterLab, please run `pip install jupyterlab --upgrade`."
26-
)
17+
if parent_process is None:
18+
return
19+
elif "jupyter-notebook" in parent_process:
20+
jupyter_notebook = optional_imports.get_module("notebook")
21+
if jupyter_notebook.__version__ < "7":
22+
# Add warning about upgrading notebook
23+
warnings.warn(
24+
f"Plotly version >= 6 requires Jupyter Notebook >= 7 but you have {jupyter_notebook.__version__} installed.\n To upgrade Jupyter Notebook, please run `pip install notebook --upgrade`."
25+
)
26+
elif "jupyter-lab" in parent_process:
27+
jupyter_lab = optional_imports.get_module("jupyterlab")
28+
if jupyter_lab.__version__ < "3":
29+
# Add warning about upgrading jupyterlab
30+
warnings.warn(
31+
f"Plotly version >= 6 requires JupyterLab >= 3 but you have {jupyter_lab.__version__} installed. To upgrade JupyterLab, please run `pip install jupyterlab --upgrade`."
32+
)
2733

2834

2935
def validate_coerce_fig_to_dict(fig, validate):

0 commit comments

Comments
 (0)