Pickle - cPickle.UnpicklingError: invalid load key, '?'
I recently had this issue when trying to unpickle a file... try using joblib
instead:
fname = 'Path_to_filename.pkl'
model = joblib.load(open(fname, 'rb'))
Otherwise - it is likely a corrupted file.
![MBT](https://i.stack.imgur.com/tRSwM.png?s=256&g=1)
MBT
Updated on June 05, 2022Comments
-
MBT about 2 years
I was trying to load data by using this repository (uses some Python 2 originally):
https://github.com/hashbangCoder/Text-SummarizationHowever I got an pickling error (using Python 2.7, I tried also Python2.6 with the same result):
>>> import cPickle as pickle >>> pickle.load(open('train.bin', 'rb'))
Error:
Traceback (most recent call last): File "<stdin>", line 1, in <module> cPickle.UnpicklingError: invalid load key, '?'.
I tried also with Python3 but without success (same for
_pickle
):import pickle pickle.load(open(path, 'rb'))
Error:
--------------------------------------------------------------------------- UnpicklingError Traceback (most recent call last) <ipython-input-9-0129e43fa781> in <module>() ----> 1 data = pickle.load(open(path, 'rb'), encoding='utf8') UnpicklingError: invalid load key, '\xd9'.
There are plenty of questions out there dealing with this error, but I haven't found anything that solves my problem.
I tried also on different systems and downloaded it twice to be sure that the file wasn't corrupted during the download. I'm also getting similar errors for the other files.
So I guess it may be some kind of version or encoding problem here?Any idea what I can try to load the file?
Thanks in advance!