简体   繁体   中英

Loading a pickle package in AWS EC2 instance

I have saved one of my models in local using pickle (windows Python 3.6), I needed that model to run on an EC2 Linux instance (using Python 2.7) to make predictions. I had transferred the saved model from my laptop to EC2 instance using Filezilla, now when I am trying to load the model using the following code:

filename = 'Customer_segmentation_model_xgb_final.sav'
loaded_model = pickle.load(open(filename,'rb'))

It gives the following error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib64/python2.7/pickle.py", line 1384, in load
    return Unpickler(file).load()
  File "/usr/lib64/python2.7/pickle.py", line 864, in load
    dispatch[key](self)
  File "/usr/lib64/python2.7/pickle.py", line 892, in load_proto
    raise ValueError, "unsupported pickle protocol: %d" % proto
ValueError: unsupported pickle protocol: 3

Someone please suggest what I am doing wrong and what needs to be done.

It looks like a compatibility problem, I would suggest to install the same version of Python on your server (python 3.6) since the pickle module is part of the Python standard library:

sudo apt-get install python3.6

You could also force a lower protocol when you dump initially ( EDIT : like proposed in the comments):

pickle.dump(model, file, protocol=2)

Hope this helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM