No module named 'xgboost' when using pickle

Hi, I am trying to deploy a xgboost classifier using streamlit. I have the model trained in a jupyter notebook file in a different folder. in the folder that has the streamlit python script, i have installed venv and im running the app through the virtual environment. streamlit works perfectly but when I try to predict using the loaded pickle file, i get an error ‘no module named xgboost’ in it. so i did install xgboost inside the virtual environment, and when i try to run again i get the error ‘super object has no attribute get_params’.

image

and the code used to import the pickled model
data = np.array(inputs)
ser = pd.Series(data)
with open(‘xgb_classifier_model.pickle’,‘rb’) as modelFile:
model = pickle.load(modelFile)

prediction = model.predict(ser.to_frame().transpose())

my first question is - do i necessarily need to install xgboost and import it in the main app.py script? (ive used the trained model in a jupyter notebook, different than the one in which it was trained, by using pickle and it ran perfectly)
my second question is - even if i install xgboost, i get the new error. is there a way to fix it?

any help would be really appreciated. i have attached the github repo link - GitHub - rohithandique/maverick-web-app

1 Like

Hello, I had the second issue you mentioned, where ‘super’ object has no attribute ‘get_params’.

I was trying to predict from a model (made in the env using xgboost v1.3.3) loaded from pickle when xgboost (v1.5.0) is installed on the environment. I then made sure to use xgboost v1.3.3 for predicting and it’s not throwing any errors!

1 Like