New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
tqdm.auto errors in notebooks if ipywidgets is not installed #1082
Comments
Use tqdm.auto to get a progressbar appropriate to the environment (e.g tqdm.notebook.tqdm for Jupyter Notebook). Falls back to standard tqdm.tqdm if an ImportError is encountered (as described in tqdm/tqdm#1082)
This bug also causes an error when using any of the "contrib" features in a notebook without [...]
--> 377 return list(tmap(func, iterable, **kwargs))
File .../python3.9/site-packages/tqdm/contrib/__init__.py:97, in tmap(function, *sequences, **tqdm_kwargs)
88 @builtin_iterable
89 def tmap(function, *sequences, **tqdm_kwargs):
90 """
91 Equivalent of builtin `map`.
92
(...)
95 tqdm_class : [default: tqdm.auto.tqdm].
96 """
---> 97 for i in tzip(*sequences, **tqdm_kwargs):
98 yield function(*i)
File .../python3.9/site-packages/tqdm/contrib/__init__.py:84, in tzip(iter1, *iter2plus, **tqdm_kwargs)
82 kwargs = tqdm_kwargs.copy()
83 tqdm_class = kwargs.pop("tqdm_class", tqdm_auto)
---> 84 for i in zip(tqdm_class(iter1, **kwargs), *iter2plus):
85 yield i
File .../python3.9/site-packages/tqdm/notebook.py:242, in tqdm_notebook.__init__(self, *args, **kwargs)
240 unit_scale = 1 if self.unit_scale is True else self.unit_scale or 1
241 total = self.total * unit_scale if self.total else self.total
--> 242 self.container = self.status_printer(self.fp, total, self.desc, self.ncols)
243 self.container.pbar = proxy(self)
244 self.displayed = False
File .../python3.9/site-packages/tqdm/notebook.py:115, in tqdm_notebook.status_printer(_, total, desc, ncols)
106 # Fallback to text bar if there's no total
107 # DEPRECATED: replaced with an 'info' style bar
108 # if not total:
(...)
112
113 # Prepare IPython progress bar
114 if IProgress is None: # #187 #451 #558 #872
--> 115 raise ImportError(
116 "IProgress not found. Please update jupyter and ipywidgets."
117 " See https://ipywidgets.readthedocs.io/en/stable"
118 "/user_install.html")
119 if total:
120 pbar = IProgress(min=0, max=total)
ImportError: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html |
Even though the error is raised by design, given the number of people who expect different behaviour - probably worth a graceful fallback indeed (with a warning rather than an error). |
Sorry for the massive delay in reviewing. Addressed in v4.63.0 :) |
read the [known issues]
environment, where applicable:
Example
Created a conda environment with:
Using that environment, in a notebook:
output of conda list
pic
Why this is a problem
I would like my package to have nice progress bars wherever it's used, and not error because of them. I don't want any notebook related as dependencies for my package. I think it makes sense for
tqdm.auto
to make a choice which will not error.This issue has come up a few times elsewhere
What I think should happen
If
ipywidgets
is not available,from tqdm.auto import tqdm
should not import atqdm
class that relies onipywidgets
. It could just importtqdm.tqdm
.The text was updated successfully, but these errors were encountered: