ValueError: unsupported pickle protocol: 3, python2 pickle can not load the file dumped by python 3 pickle?

前端 未结 2 1338
陌清茗
陌清茗 2020-12-07 16:05

I use pickle to dump a file on python 3, and I use pickle to load the file on python 2, the ValueError appears.

So, python 2 pickle can not load the file dumped by

2条回答
  •  离开以前
    2020-12-07 16:21

    Pickle uses different protocols to convert your data to a binary stream.

    • In python 2 there are 3 different protocols (0, 1, 2) and the default is 0.

    • In python 3 there are 5 different protocols (0, 1, 2, 3, 4) and the default is 3.

    You must specify in python 3 a protocol lower than 3 in order to be able to load the data in python 2. You can specify the protocol parameter when invoking pickle.dump.

提交回复
热议问题