eelbrain.load.convert_pickle_protocol

eelbrain.load.convert_pickle_protocol(root=None, to_protocol=4, pattern='**/*.pickle')

Load and re-save pickle files with a specific protocol

Parameters
  • root (Union[Path, str, None]) – Root directory to look for pickle files.

  • to_protocol (int) – Protocol to re-save with.

  • pattern (str) – Filename pattern used to find pickle files (default is all *.pickle files under root).

Notes

Python 3.8 introduced a new pickle protocol 5, which older versions of Python can’t read. Trying to unpickle such files results in the following error:

ValueError: unsupported pickle protocol: 5

A simple solution to make those files readable in Python 3.7 and below is to use Python 3.8 to load these files and re-save them with a lower protocol version (e.g., version 4). The convert_pickle_protocol function allows doing that for a large number of files with a single command (by default, to all files in the root directory).