TypeError: an integer is required (got type bytes) while loading the pickle file

Viewed 1348

It throws below error while loading the pickle file. return types.CodeType( TypeError: an integer is required (got type bytes)

if __model is None:

    with open('banglore_home_prices_model_2.pickle', 'rb') as f:
        __model = pickle.load(f) - > Error is raised for this line of code
    print(__model)

Looks like the error is actually raised by cloudpickle, Not sure this is raised bcz of conflicting versions.if someone have come across this issue, let me know what helped you to fix this issue.
I have created virtual environment for this project and installed the requirements. I'am using python3 version.

1 Answers

you are reading file as "rb" mode as it opens the file in binary format for reading

  • try this
import pickle
pickle.load('banglore_home_prices_model_2.pickle')
  • or load it using joblib
from joblib import load
model = load('banglore_home_prices_model_2.pickle')
Related