Skip to content

Commit fc8eff2

Browse files
committed
Move warnings out of utils file to avoid psutils import error
1 parent 3a85b8a commit fc8eff2

File tree

2 files changed

+31
-29
lines changed

2 files changed

+31
-29
lines changed

packages/python/plotly/plotly/io/_renderers.py

+31
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,37 @@
3535
ipython_display = optional_imports.get_module("IPython.display")
3636
nbformat = optional_imports.get_module("nbformat")
3737

38+
from plotly import optional_imports
39+
40+
import warnings
41+
import psutil
42+
43+
44+
def display_jupyter_version_warnings():
45+
parent_process = None
46+
try:
47+
parent_process = psutil.Process().parent().cmdline()[-1]
48+
except Exception:
49+
pass
50+
51+
if parent_process is None:
52+
return
53+
elif "jupyter-notebook" in parent_process:
54+
jupyter_notebook = optional_imports.get_module("notebook")
55+
if jupyter_notebook.__version__ < "7":
56+
# Add warning about upgrading notebook
57+
warnings.warn(
58+
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`."
59+
)
60+
elif "jupyter-lab" in parent_process:
61+
jupyter_lab = optional_imports.get_module("jupyterlab")
62+
if jupyter_lab.__version__ < "3":
63+
# Add warning about upgrading jupyterlab
64+
warnings.warn(
65+
f"Plotly version >= 6 requires JupyterLab >= 3 but you have {jupyter_lab.__version__} installed. To upgrade JupyterLab, please run `pip install jupyterlab --upgrade`."
66+
)
67+
68+
3869
# Renderer configuration class
3970
# -----------------------------
4071
class RenderersConfig(object):

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

-29
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,6 @@
11
import plotly
22
import plotly.graph_objs as go
33
from plotly.offline import get_plotlyjs_version
4-
from plotly import optional_imports
5-
6-
import warnings
7-
import psutil
8-
9-
10-
def display_jupyter_version_warnings():
11-
parent_process = None
12-
try:
13-
parent_process = psutil.Process().parent().cmdline()[-1]
14-
except Exception:
15-
pass
16-
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-
)
334

345

356
def validate_coerce_fig_to_dict(fig, validate):

0 commit comments

Comments
 (0)