progressbar33 - Text Progress Bar
progressbar33 is a Python library for creating customizable text-based progress bars in terminal applications. It provides a simple API to display progress for long-running operations. The current version is 2.4, and its development appears to be in maintenance mode with infrequent updates.
Common errors
-
ModuleNotFoundError: No module named 'progressbar33'
cause The Python package `progressbar33` installs an internal module named `progressbar`, not `progressbar33`.fixChange your import statement from `from progressbar33 import ...` to `from progressbar import ...`. -
AttributeError: 'ProgressBar' object has no attribute 'finish'
cause This error typically occurs if the `finish()` method was not explicitly called after the progress bar completed, and the `with` statement context manager was not used.fixEnsure you either use a `with` statement: `with ProgressBar(...) as bar:` or manually call `bar.finish()` after your loop: `bar = ProgressBar(...).start(); ...; bar.finish()`. -
TypeError: object of type 'ProgressBar' has no len()
cause The `ProgressBar` instance needs to know the total number of iterations to correctly display percentage and ETA, especially when iterating over a finite sequence. This error indicates `max_value` was not set.fixInitialize `ProgressBar` with `max_value` set to the total count: `bar = ProgressBar(max_value=total_iterations)`. -
SyntaxError: invalid syntax (on Python 2.x)
cause progressbar33 is a Python 3.4+ library and contains syntax incompatible with Python 2.x.fixRun your application with a Python 3.x interpreter (specifically 3.4 or newer).
Warnings
- breaking Namespace Collision: Installing `progressbar33` will install a module named `progressbar`. If the more actively maintained `progressbar` library (PyPI: `progressbar`, often used with `import progressbar`) is also installed or intended to be used, this will lead to conflicts and unpredictable behavior, as both attempt to provide `import progressbar`. It is strongly recommended to use separate virtual environments or choose only one library.
- gotcha Python 3 Only: Despite `requires_python: None` being listed on PyPI, the library explicitly requires Python 3.4 or higher as per its `setup.py` (`python_requires='>=3.4'`). Attempting to use it with Python 2.x will result in compatibility errors.
- gotcha Forgetting `bar.finish()`: If you do not use the `with` statement context manager when creating your `ProgressBar` instance, you must explicitly call `bar.finish()` after the loop or process completes. Failing to do so will leave the progress bar display incomplete or improperly terminated.
- gotcha `max_value` for finite iterables: For processes where the total number of iterations is known (e.g., iterating over a list or range), `max_value` must be explicitly set when initializing `ProgressBar`. If `max_value` is not set for a finite process, the progress bar may not display percentage or ETA correctly.
Install
-
pip install progressbar33
Imports
- ProgressBar
from progressbar33 import ProgressBar
from progressbar import ProgressBar
- widgets
from progressbar import Percentage, Bar, ETA
Quickstart
import time
from progressbar import ProgressBar, Percentage, Bar, RotatingMarker, ETA
# Define widgets for the progress bar
widgets = [
'Processing: ', Percentage(),
' ', Bar(marker=RotatingMarker()),
' ', ETA(),
]
# Initialize the progress bar with a maximum value
max_items = 50
with ProgressBar(widgets=widgets, max_value=max_items) as bar:
for i in range(max_items):
# Simulate some work
time.sleep(0.1)
# Update the progress bar
bar.update(i + 1)
print('\nTask Completed!')