Python 3.7 Error: Unsupported Pickle Protocol 5

Python 3.7 Error: Unsupported Pickle Protocol 5

For pandas users who saved a dataframe to a pickle file with protocol 5 in python 3.8 and need to load it into python 3.6 which only supports protocol 4 (Im looking at you google colab):

!pip3 install pickle5
import pickle5 as pickle
with open(path_to_protocol5, rb) as fh:
  data = pickle.load(fh)

Could also save into a protocol-4 pickle from python 3.6


Update: If facing this when loading a model from stable-baselines3:

!pip install --upgrade --quiet cloudpickle pickle5
from stable_baselines3 import PPO
# restart kernel if in jupyter notebook

# Might not need this dict in all cases
custom_objects = {
    lr_schedule: lambda x: .003,
    clip_range: lambda x: .02
model = PPO.load(path/to/, custom_objects=custom_objects)

Tested on 2021-05-31 with env:

cloudpickle: 1.6.0
pickle5: 0.0.11 
stable-baselines3: 1.0


Use pickle5 or load it into python 3.8+ and then serialize it to a lower version of it using the protocol parameter.

Python 3.7 Error: Unsupported Pickle Protocol 5

In the event that you cannot load pickle5 because of its dependencies (mainly Visual Building c++), another solution could be that you change the Python interpreter youre using (to the old one, before the error occured). For me, I was getting this error after I ran a program in IDLE that I had been running in Spyder. When I ran it again within Spyder, it dropped this error.

Python Error: Unsupported Pickle Protocol 5 

To resolve this, within Spyder I changed my Python interpreter to the Python I was using with IDLE (Tools -> Preferences). Once I rebooted Spyder, I had to install the necessary dependencies with command prompt so that within Spyder the console could be used:

pip install spyder-kernels

Naturally, this may introduce some irregularities within Spyder (namely, packages its supposed to come with are no longer there because of the different interpreter). These should easily be sussed out when debugging, and resolved using standard pip installs.

Once you recover your (thought to be lost) files, it might be wise to think about reverting back to Spyders Python interpreter, and updating code to elegantly handle this problem (I would love if somebody could suggest in comments how to do this that didnt require pickle5!)

Leave a Reply

Your email address will not be published. Required fields are marked *