# Buggy code
def __init__(self, *args, **kwargs):
    # Setup default output
    if kwargs.get("file", sys.stderr) is sys.stderr:
        kwargs["file"] = sys.stdout  # avoid the red block in IPython

    # Remove the bar from the printed string, only print stats
    if not kwargs.get("bar_format", None):
        kwargs["bar_format"] = r"{n}/|/{l_bar}{r_bar}"

    # Initialize parent class + avoid printing by using gui=True
    kwargs["gui"] = True
    super(tqdm_notebook, self).__init__(*args, **kwargs)
    if self.disable or not kwargs["gui"]:
        return

    # Get bar width
    self.ncols = "100%" if self.dynamic_ncols else kwargs.get("ncols", None)

    # Replace with IPython progress bar display (with correct total)
    unit_scale = 1 if self.unit_scale is True else self.unit_scale or 1
    total = self.total * unit_scale if self.total else self.total
    self.container = self.status_printer(self.fp, total, self.desc, self.ncols)
    self.sp = self.display

    # Print initial bar state
    if not self.disable:
        self.display()


# Traceback (TypeError)
for _ in tqdm_notebook(range(10), ncols='400px', bar_format='{bar}'):
sleep(0.1)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-3-aced8917afa9> in <module>()
1 # px ncols
----> 2 for _ in tqdm_notebook(range(10),ncols='400px', bar_format='{bar}'): #400px
3     sleep(0.1)

/usr/local/anaconda/lib/python3.6/site-packages/tqdm/__init__.py in tqdm_notebook(*args, **kwargs)
23     """See tqdm._tqdm_notebook.tqdm_notebook for full documentation"""
24     from ._tqdm_notebook import tqdm_notebook as _tqdm_notebook
---> 25     return _tqdm_notebook(*args, **kwargs)
26
27

/usr/local/anaconda/lib/python3.6/site-packages/tqdm/_tqdm_notebook.py in __init__(self, *args, **kwargs)
203         # Print initial bar state
204         if not self.disable:
--> 205             self.sp(self.__repr__())  # same as self.refresh without clearing
206
207     def __iter__(self, *args, **kwargs):

/usr/local/anaconda/lib/python3.6/site-packages/tqdm/_tqdm.py in __repr__(self, elapsed)
890             self.desc, self.ascii, self.unit,
891             self.unit_scale, 1 / self.avg_time if self.avg_time else None,
--> 892             self.bar_format, self.postfix, self.unit_divisor)
893
894     @property

/usr/local/anaconda/lib/python3.6/site-packages/tqdm/_tqdm.py in format_meter(n, total, elapsed, ncols, prefix, ascii, unit, unit_scale, rate, bar_format, postfix, unit_divisor)
363             # Formatting progress bar
364             # space available for bar's display
--> 365             N_BARS = max(1, ncols - len(l_bar) - len(r_bar)) if ncols \
366                 else 10
367

TypeError: unsupported operand type(s) for -: 'str' and 'int'

# Fixed code
def __init__(self, *args, **kwargs):
    # Setup default output
    if kwargs.get("file", sys.stderr) is sys.stderr:
        kwargs["file"] = sys.stdout  # avoid the red block in IPython

    # Initialize parent class + avoid printing by using gui=True
    kwargs["gui"] = True
    kwargs.setdefault("bar_format", "{l_bar}{bar}{r_bar}")
    kwargs["bar_format"] = kwargs["bar_format"].replace("{bar}", "<bar/>")
    super(tqdm_notebook, self).__init__(*args, **kwargs)
    if self.disable or not kwargs["gui"]:
        return

    # Get bar width
    self.ncols = "100%" if self.dynamic_ncols else kwargs.get("ncols", None)

    # Replace with IPython progress bar display (with correct total)
    unit_scale = 1 if self.unit_scale is True else self.unit_scale or 1
    total = self.total * unit_scale if self.total else self.total
    self.container = self.status_printer(self.fp, total, self.desc, self.ncols)
    self.sp = self.display

    # Print initial bar state
    if not self.disable:
        self.display()