GuPe
GuPe

Reputation: 297

How to use a tqdm progress bar in Jupyter?

I am coding an interface using the Jupyter widgets where the user configures a bunch of settings and then clicks a "Run" button. On clicking, this button calls a function implemented in another module. That function takes some time to run, so I added to it a progress bar using the tqdm package. Unfortunately, when I click "Run", this progress bar is now displayed in another terminal, rather than within the output of the cell. Is there a way to have the bar be displayed within the same cell output?

Upvotes: 7

Views: 13916

Answers (1)

Simon Bowly
Simon Bowly

Reputation: 1073

There is a submodule of tqdm with jupyter integration: https://github.com/tqdm/tqdm#ipython-jupyter-integration. If you already have widgets enabled it should work out of the box. Just replace any tqdm calls with their equivalent from the tdqm.notebook submodule, i.e. import

from tqdm.notebook import trange, tqdm

instead of

from tqdm import trange, tqdm

This assumes you are actually calling tqdm directly in the notebook and the call is not buried in your other module code. If that's the case you might need to pass an argument through or patch the tqdm calls.

Upvotes: 7

Related Questions