Skip to content
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

Closed
5 of 8 tasks
ivirshup opened this issue Nov 25, 2020 · 3 comments · Fixed by #1302
Closed
5 of 8 tasks

tqdm.auto errors in notebooks if ipywidgets is not installed #1082

ivirshup opened this issue Nov 25, 2020 · 3 comments · Fixed by #1302
Assignees
Labels
c1-quick 🕐 Complexity low p0-bug-critical ☢ Exception rasing question/docs ‽ Documentation clarification candidate submodule-notebook 📓 Much web such IDE to-fix ⌛ In progress
Projects

Comments

@ivirshup
Copy link

ivirshup commented Nov 25, 2020

  • I have marked all applicable categories:
    • exception-raising bug
    • visual output bug
    • documentation request (i.e. "X is missing from the documentation." If instead I want to ask "how to use X?" I understand [StackOverflow#tqdm] is more appropriate)
    • new feature request
  • I have visited the [source website], and in particular
    read the [known issues]
  • I have searched through the [issue tracker] for duplicates
  • I have mentioned version numbers, operating system and
    environment, where applicable:
    import tqdm, sys
    print(tqdm.__version__, sys.version, sys.platform)
4.51.0 3.8.5 (default, Sep  4 2020, 02:22:02) 
[Clang 10.0.0 ] darwin

Example

Created a conda environment with:

$ conda create -yn tqdm_nowidgets python=3.8 tqdm ipython notebook

Using that environment, in a notebook:

from tqdm.auto import tqdm
from time import sleep

for i in tqdm(range(100)):
    sleep(0.05)
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-3-542c7d78a2ff> in <module>
----> 1 for i in tqdm(range(100)):
      2     sleep(0.05)

~/miniconda3/envs/tqdm_nowidgets/lib/python3.8/site-packages/tqdm/notebook.py in __init__(self, *args, **kwargs)
    221         unit_scale = 1 if self.unit_scale is True else self.unit_scale or 1
    222         total = self.total * unit_scale if self.total else self.total
--> 223         self.container = self.status_printer(
    224             self.fp, total, self.desc, self.ncols)
    225         self.sp = self.display

~/miniconda3/envs/tqdm_nowidgets/lib/python3.8/site-packages/tqdm/notebook.py in status_printer(_, total, desc, ncols)
     94         # Prepare IPython progress bar
     95         if IProgress is None:  # #187 #451 #558 #872
---> 96             raise ImportError(
     97                 "IProgress not found. Please update jupyter and ipywidgets."
     98                 " See https://ipywidgets.readthedocs.io/en/stable"

ImportError: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html
output of conda list
# packages in environment at /Users/isaac/miniconda3/envs/tqdm_nowidgets:
#
# Name                    Version                   Build  Channel
appnope                   0.1.0                 py38_1001  
argon2-cffi               20.1.0           py38haf1e3a3_1  
async_generator           1.10                       py_0  
attrs                     20.3.0             pyhd3eb1b0_0  
backcall                  0.2.0                      py_0  
bleach                    3.2.1                      py_0  
ca-certificates           2020.10.14                    0  
certifi                   2020.11.8        py38hecd8cb5_0  
cffi                      1.14.3           py38h2125817_2  
decorator                 4.4.2                      py_0  
defusedxml                0.6.0                      py_0  
entrypoints               0.3                      py38_0  
importlib-metadata        2.0.0                      py_1  
importlib_metadata        2.0.0                         1  
ipykernel                 5.3.4            py38h5ca1d4c_0  
ipython                   7.19.0           py38h01d92e1_0  
ipython_genutils          0.2.0                    py38_0  
jedi                      0.17.2                   py38_0  
jinja2                    2.11.2                     py_0  
jsonschema                3.2.0                      py_2  
jupyter_client            6.1.7                      py_0  
jupyter_core              4.7.0            py38hecd8cb5_0  
jupyterlab_pygments       0.1.2                      py_0  
libcxx                    10.0.0                        1  
libedit                   3.1.20191231         h1de35cc_1  
libffi                    3.3                  hb1e8313_2  
libsodium                 1.0.18               h1de35cc_0  
markupsafe                1.1.1            py38h1de35cc_1  
mistune                   0.8.4           py38h1de35cc_1001  
nbclient                  0.5.1                      py_0  
nbconvert                 6.0.7                    py38_0  
nbformat                  5.0.8                      py_0  
ncurses                   6.2                  h0a44026_1  
nest-asyncio              1.4.3              pyhd3eb1b0_0  
notebook                  6.1.4                    py38_0  
openssl                   1.1.1h               haf1e3a3_0  
packaging                 20.4                       py_0  
pandoc                    2.11                 h0dc7051_0  
pandocfilters             1.4.3            py38hecd8cb5_1  
parso                     0.7.0                      py_0  
pexpect                   4.8.0              pyhd3eb1b0_3  
pickleshare               0.7.5                 py38_1001  
pip                       20.2.4           py38hecd8cb5_0  
prometheus_client         0.8.0                      py_0  
prompt-toolkit            3.0.8                      py_0  
ptyprocess                0.6.0              pyhd3eb1b0_2  
pycparser                 2.20                       py_2  
pygments                  2.7.2              pyhd3eb1b0_0  
pyparsing                 2.4.7                      py_0  
pyrsistent                0.17.3           py38haf1e3a3_0  
python                    3.8.5                h26836e1_1  
python-dateutil           2.8.1                      py_0  
pyzmq                     19.0.2           py38hb1e8313_1  
readline                  8.0                  h1de35cc_0  
send2trash                1.5.0                    py38_0  
setuptools                50.3.1           py38hecd8cb5_1  
six                       1.15.0           py38hecd8cb5_0  
sqlite                    3.33.0               hffcf06c_0  
terminado                 0.9.1                    py38_0  
testpath                  0.4.4                      py_0  
tk                        8.6.10               hb0a8c7a_0  
tornado                   6.0.4            py38h1de35cc_1  
tqdm                      4.51.0             pyhd3eb1b0_0  
traitlets                 5.0.5                      py_0  
wcwidth                   0.2.5                      py_0  
webencodings              0.5.1                    py38_1  
wheel                     0.35.1             pyhd3eb1b0_0  
xz                        5.2.5                h1de35cc_0  
zeromq                    4.3.3                hb1e8313_3  
zipp                      3.4.0              pyhd3eb1b0_0  
zlib                      1.2.11               h1de35cc_3  
pic

image

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 a tqdm class that relies on ipywidgets. It could just import tqdm.tqdm.

duckontheweb added a commit to radiantearth/radiant-mlhub that referenced this issue Feb 8, 2021
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)
@bdice
Copy link

bdice commented Feb 27, 2022

This bug also causes an error when using any of the "contrib" features in a notebook without ipywidgets. All the iterables like tmap, tzip, tenumerate and concurrency features like process_map and thread_map accept an argument tqdm_class that defaults to tqdm.auto.tqdm. However, using that automatic class results in a traceback like the following if ipywidgets is unavailable when running in a notebook. I can confirm that #1218 fixes this bug. (Note that #1148 fixed a related issue with passing tqdm_class to tmap / tzip.)

[...]
--> 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

@casperdcl casperdcl self-assigned this Feb 27, 2022
@casperdcl casperdcl added c1-quick 🕐 Complexity low p0-bug-critical ☢ Exception rasing question/docs ‽ Documentation clarification candidate submodule-notebook 📓 Much web such IDE to-fix ⌛ In progress labels Feb 27, 2022
@casperdcl
Copy link
Sponsor Member

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).

@casperdcl casperdcl added this to Next Release in Casper Feb 27, 2022
casperdcl added a commit that referenced this issue Feb 27, 2022
casperdcl added a commit that referenced this issue Feb 27, 2022
Casper automation moved this from Next Release to Done Feb 28, 2022
@casperdcl
Copy link
Sponsor Member

casperdcl commented Feb 28, 2022

Sorry for the massive delay in reviewing. Addressed in v4.63.0 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c1-quick 🕐 Complexity low p0-bug-critical ☢ Exception rasing question/docs ‽ Documentation clarification candidate submodule-notebook 📓 Much web such IDE to-fix ⌛ In progress
Projects
Casper
  
Done
3 participants