I'm running a bunch of models. Because the code takes a long time to run, I pickle a few objects so I can load them back in later without having to redo everything. This is the code that I use to pickle and unpickle my objects:
def export_model(m, fname='model.pkl'):
f = open(fname, 'wb')
pickle.dump(m, f)
f.close()
def import_model(fname):
file = open(fname, 'rb')
m = pickle.load(file)
return m
It seems pretty straightforward and it's worked without issues on my Macbook. The problem comes when I try to run the code on a separate Windows machine. I can re-import the objects without any issues on the Windows computer. But when I try to use those same .pkl files to my Mac, pickle.load gives the following error:
TypeError: __randomstate_ctor() takes from 0 to 1 positional arguments but 2 were given
I checked that both computers are using the same format version:
print(pickle.format_version)
>>> 4.0
I'm a bit puzzled since the only difference is that the Windows machine is running Python 3.11.3 while the Mac is running 3.8.8. The code running on the two machines is the same (it's the same repository) so there shouldn't be any other discrepancies. Is this a Python version issue or a cross-platform issue?