# Buggy code
def status_printer(_, total=None, desc=None, ncols=None):
    """
    Manage the printing of an IPython/Jupyter Notebook progress bar widget.
    """
    # Fallback to text bar if there's no total
    # DEPRECATED: replaced with an 'info' style bar
    # if not total:
    #    return super(tqdm_notebook, tqdm_notebook).status_printer(file)

    # fp = file

    # Prepare IPython progress bar
    if total:
        pbar = IntProgress(min=0, max=total)
    else:  # No total? Show info style bar with no progress tqdm status
        pbar = IntProgress(min=0, max=1)
        pbar.value = 1
        pbar.bar_style = "info"
    if desc:
        pbar.description = desc
    # Prepare status text
    ptext = HTML()
    # Only way to place text to the right of the bar is to use a container
    container = HBox(children=[pbar, ptext])
    # Prepare layout
    if ncols is not None:  # use default style of ipywidgets
        # ncols could be 100, "100px", "100%"
        ncols = str(ncols)  # ipywidgets only accepts string
        if ncols[-1].isnumeric():
            # if last value is digit, assume the value is digit
            ncols += "px"
        pbar.layout.flex = "2"
        container.layout.width = ncols
        container.layout.display = "inline-flex"
        container.layout.flex_flow = "row wrap"
    display(container)

    def print_status(s="", close=False, bar_style=None, desc=None):
        # Note: contrary to native tqdm, s='' does NOT clear bar
        # goal is to keep all infos if error happens so user knows
        # at which iteration the loop failed.

        # Clear previous output (really necessary?)
        # clear_output(wait=1)

        # Get current iteration value from format_meter string
        if total:
            # n = None
            if s:
                npos = s.find(r"/|/")  # cause we use bar_format=r'{n}|...'
                # Check that n can be found in s (else n > total)
                if npos >= 0:
                    n = int(s[:npos])  # get n from string
                    s = s[npos + 3 :]  # remove from string

                    # Update bar with current n value
                    if n is not None:
                        pbar.value = n

        # Print stats
        if s:  # never clear the bar (signal: s='')
            s = s.replace("||", "")  # remove inesthetical pipes
            s = escape(s)  # html escape special characters (like '?')
            ptext.value = s

        # Change bar style
        if bar_style:
            # Hack-ish way to avoid the danger bar_style being overriden by
            # success because the bar gets closed after the error...
            if not (pbar.bar_style == "danger" and bar_style == "success"):
                pbar.bar_style = bar_style

        # Special signal to close the bar
        if close and pbar.bar_style != "danger":  # hide only if no error
            try:
                container.close()
            except AttributeError:
                container.visible = False

        # Update description
        if desc:
            pbar.description = desc

    return print_status


# Traceback (NameError)
NameError                                 Traceback (most recent call last)
<ipython-input-6-207cef0f8cd2> in <module>()
1 import tqdm
----> 2 for i in tqdm.tqdm_notebook(range(1000000)):
3     i * 2

~/.local/lib/python3.4/site-packages/tqdm/__init__.py in tqdm_notebook(*args, **kwargs)
17     """See tqdm._tqdm_notebook.tqdm_notebook for full documentation"""
18     from ._tqdm_notebook import tqdm_notebook as _tqdm_notebook
---> 19     return _tqdm_notebook(*args, **kwargs)
20
21

~/.local/lib/python3.4/site-packages/tqdm/_tqdm_notebook.py in __init__(self, *args, **kwargs)
182         # self.sp('', close=True)
183         # Replace with IPython progress bar display (with correct total)
--> 184         self.sp = self.status_printer(self.fp, self.total, self.desc)
185         self.desc = None  # trick to place description before the bar
186

~/.local/lib/python3.4/site-packages/tqdm/_tqdm_notebook.py in status_printer(file, total, desc)
103         # Prepare IPython progress bar
104         if total:
--> 105             pbar = IntProgress(min=0, max=total)
106         else:  # No total? Show info style bar with no progress tqdm status
107             pbar = IntProgress(min=0, max=1)

NameError: name 'IntProgress' is not defined

# Fixed code
def status_printer(_, total=None, desc=None, ncols=None):
    """
    Manage the printing of an IPython/Jupyter Notebook progress bar widget.
    """
    # Fallback to text bar if there's no total
    # DEPRECATED: replaced with an 'info' style bar
    # if not total:
    #    return super(tqdm_notebook, tqdm_notebook).status_printer(file)

    # fp = file

    # Prepare IPython progress bar
    try:
        if total:
            pbar = IntProgress(min=0, max=total)
        else:  # No total? Show info style bar with no progress tqdm status
            pbar = IntProgress(min=0, max=1)
            pbar.value = 1
            pbar.bar_style = "info"
    except NameError:
        # #187 #451 #558
        raise ImportError(
            "IntProgress not found. Please update juputer and ipywidgets."
            " See https://ipywidgets.readthedocs.io/en/stable"
            "/user_install.html"
        )

    if desc:
        pbar.description = desc
    # Prepare status text
    ptext = HTML()
    # Only way to place text to the right of the bar is to use a container
    container = HBox(children=[pbar, ptext])
    # Prepare layout
    if ncols is not None:  # use default style of ipywidgets
        # ncols could be 100, "100px", "100%"
        ncols = str(ncols)  # ipywidgets only accepts string
        if ncols[-1].isnumeric():
            # if last value is digit, assume the value is digit
            ncols += "px"
        pbar.layout.flex = "2"
        container.layout.width = ncols
        container.layout.display = "inline-flex"
        container.layout.flex_flow = "row wrap"
    display(container)

    def print_status(s="", close=False, bar_style=None, desc=None):
        # Note: contrary to native tqdm, s='' does NOT clear bar
        # goal is to keep all infos if error happens so user knows
        # at which iteration the loop failed.

        # Clear previous output (really necessary?)
        # clear_output(wait=1)

        # Get current iteration value from format_meter string
        if total:
            # n = None
            if s:
                npos = s.find(r"/|/")  # cause we use bar_format=r'{n}|...'
                # Check that n can be found in s (else n > total)
                if npos >= 0:
                    n = int(s[:npos])  # get n from string
                    s = s[npos + 3 :]  # remove from string

                    # Update bar with current n value
                    if n is not None:
                        pbar.value = n

        # Print stats
        if s:  # never clear the bar (signal: s='')
            s = s.replace("||", "")  # remove inesthetical pipes
            s = escape(s)  # html escape special characters (like '?')
            ptext.value = s

        # Change bar style
        if bar_style:
            # Hack-ish way to avoid the danger bar_style being overriden by
            # success because the bar gets closed after the error...
            if not (pbar.bar_style == "danger" and bar_style == "success"):
                pbar.bar_style = bar_style

        # Special signal to close the bar
        if close and pbar.bar_style != "danger":  # hide only if no error
            try:
                container.close()
            except AttributeError:
                container.visible = False

        # Update description
        if desc:
            pbar.description = desc

    return print_status