diff --git a/tqdm/autonotebook.py b/tqdm/autonotebook.py index b032061bf..1f2258146 100644 --- a/tqdm/autonotebook.py +++ b/tqdm/autonotebook.py @@ -8,6 +8,7 @@ """ import os import sys +from warnings import warn try: get_ipython = sys.modules['IPython'].get_ipython @@ -15,11 +16,14 @@ raise ImportError("console") if 'VSCODE_PID' in os.environ: # pragma: no cover raise ImportError("vscode") + from .notebook import WARN_NOIPYW, IProgress + if IProgress is None: + from .std import TqdmWarning + warn(WARN_NOIPYW, TqdmWarning, stacklevel=2) + raise ImportError('ipywidgets') except Exception: from .std import tqdm, trange else: # pragma: no cover - from warnings import warn - from .notebook import tqdm, trange from .std import TqdmExperimentalWarning warn("Using `tqdm.autonotebook.tqdm` in notebook mode." diff --git a/tqdm/notebook.py b/tqdm/notebook.py index 1f488d25f..ea44c9d00 100644 --- a/tqdm/notebook.py +++ b/tqdm/notebook.py @@ -71,6 +71,9 @@ __author__ = {"github.com/": ["lrq3000", "casperdcl", "alexanderkuk"]} __all__ = ['tqdm_notebook', 'tnrange', 'tqdm', 'trange'] +WARN_NOIPYW = ("IProgress not found. Please update jupyter and ipywidgets." + " See https://ipywidgets.readthedocs.io/en/stable" + "/user_install.html") class TqdmHBox(HBox): @@ -112,10 +115,7 @@ def status_printer(_, total=None, desc=None, ncols=None): # Prepare IPython progress bar if IProgress is None: # #187 #451 #558 #872 - raise ImportError( - "IProgress not found. Please update jupyter and ipywidgets." - " See https://ipywidgets.readthedocs.io/en/stable" - "/user_install.html") + raise ImportError(WARN_NOIPYW) if total: pbar = IProgress(min=0, max=total) else: # No total? Show info style bar with no progress tqdm status