How to fix Python Traceback.from_exception() got an unexpected keyword argument 'locals_hide_dunder'

Problem:

Your Python script crashes with the following exception when logging with structlog:

Traceback (most recent call last):
  [...]
  File "/home/uli/dev/KKS-Export/Plot.py", line 87, in create_all_plots
    device_logger.exception("Failed to plot overview", zone=zone_data.zone)
  File "/usr/local/lib/python3.10/dist-packages/structlog/_native.py", line 45, in exception
    return self.error(event, *args, **kw)
  File "/usr/local/lib/python3.10/dist-packages/structlog/_native.py", line 134, in meth
    return self._proxy_to_logger(name, event, **kw)
  File "/usr/local/lib/python3.10/dist-packages/structlog/_base.py", line 214, in _proxy_to_logger
    args, kw = self._process_event(method_name, event, event_kw)
  File "/usr/local/lib/python3.10/dist-packages/structlog/_base.py", line 165, in _process_event
    event_dict = proc(self._logger, method_name, event_dict)
  File "/usr/local/lib/python3.10/dist-packages/structlog/dev.py", line 738, in __call__
    self._exception_formatter(sio, exc_info)
  File "/usr/local/lib/python3.10/dist-packages/structlog/dev.py", line 382, in __call__
    Traceback.from_exception(
TypeError: Traceback.from_exception() got an unexpected keyword argument 'locals_hide_dunder'

Solution

Upgrade rich to 13.7.0 or later:

pip install -U "rich>=13.7.0"

Original source: structlog GitHub ticket