Stefan
Stefan

Reputation: 1934

tqdm not counting iterations in jupyter notebook

I am using tqdm to display progress of iterations. However it doesn't work properly in my jupyter notebook environment.

I can do

from tqdm import tqdm
a = 0
for i in tqdm(range(10)):
    a += i

print(a)

with output

enter image description here

This however has a problem with print statements in the loop (see here). When I do

from tqdm.notebook import tqdm
a = 0
for i in tqdm(range(10)):
    a += i

print(a)

I get

enter image description here

I.e. the iterations are executed but tqdm does not account for them.

Any idea how to fix this or what the problem might be?

The output of jupyter --version is

jupyter core     : 4.7.1
jupyter-notebook : 6.2.0
qtconsole        : not installed
ipython          : 7.20.0
ipykernel        : 5.1.0
jupyter client   : 6.1.11
jupyter lab      : not installed
nbconvert        : 5.6.1
ipywidgets       : 7.6.3
nbformat         : 5.1.2
traitlets        : 5.0.5

EDIT The problem seems to be bound to MacOS (I am running 10.15.7), since I do not observe it on CentOS.

Besides that I tried I updated my conda environment

jupyter core     : 4.7.1
jupyter-notebook : 6.2.0
qtconsole        : 5.0.2
ipython          : 7.20.0
ipykernel        : 5.5.0
jupyter client   : 6.1.11
jupyter lab      : not installed
nbconvert        : 6.0.7
ipywidgets       : 7.6.3
nbformat         : 5.1.2
traitlets        : 5.0.5

on python 3.8.8. (I also tried on 3.7.10). This issue discusses something similar and the problems seems to be related to ipywidgets.

Upvotes: 3

Views: 3752

Answers (1)

Stefan_EOX
Stefan_EOX

Reputation: 1531

I had the same issue in Jupyter Lab (3.0.9) and this worked for me:

jupyter labextension install @jupyter-widgets/jupyterlab-manager \ 
&& jupyter lab

Even though ipywidgets should install the labextension automatically, it was not listed in jupyter labextension list. When I install it manually, the progress bar works.

For classic notebooks, the ipywidgets docs mention this:

jupyter nbextension enable --py widgetsnbextension

Upvotes: 2

Related Questions