[Numpy-discussion] numpy pickling problem - python 2 vs. python 3

Pauli Virtanen pav at iki.fi
Fri Mar 6 08:55:17 EST 2015

Arnd Baecker <arnd.baecker <at> web.de> writes:
> Still I would have thought that this should be working out-of-the box,
> i.e. without the pickle.loads trick?

Pickle files should be considered incompatible between Python 2 and Python 3.

Python 3 interprets all bytes objects saved by Python 2 as str and attempts
to decode them under some unicode locale. The default locale is ASCII, so it
will simply just fail in most cases if the files contain any binary data.

Failing by default is also the right thing to do, since the saved bytes
objects might actually represent strings in some locale, and ASCII is the
safest guess.

This behavior is that of Python's pickle module, and does not depend on Numpy.

More information about the NumPy-Discussion mailing list