. Advertisement .
..3..
. Advertisement .
..4..
I get the “Valueerror: unsupported pickle protocol: 3” issue when trying to use pickle to dump a file on python 3, and I use pickle to load the file on python 2. Here is the detail of the error I got the error message:
ValueError: unsupported pickle protocol: 3, python2 pickle can not load the file dumped by python 3 pickle?
Please give me some advice to solve this problem.
The cause: Pickles’ compatibility with different Python versions is not entirely supported. An error such as “Valueerror: unsupported pickle protocol: 3” will generally result from such conversion and loading between distinct Python versions.
Solution: Python 3 should be used to write the pickled data with a lower protocol number. Return to a value of 2 that Python 2 can read since Python 3 established a new protocol with the number 3 (and takes it as default).
In
pickle.Dump
, look at theprotocol
parameter. This is how your finished code will appear.Pickle uses a different
protocols
to convert data into a binary stream.In Python 2, there are three different protocols (
0
1
2
), and the default is0
.In Python 3, there are 5 different protocols (
0
to1
,2
, and3
), with the default being3
.To load data into python 2, you must specify in Python 3 a lower protocol than
3
When invoking , you can specifyprotocol
.