Forums

Install xgboost

Hi guys,

I want to deploy a model that I fitted with xgboost. When I load the model I get the error:

no module named xgboost

First I am surprised I need to import that since the object should have all information needed. Anyhow, maybe I am missing something. But when I explicitly write "import xgboost" I get the same error. But in the bash console I get the feedback, that the package is installed:

19:59 ~ $ workon my-virtualenv
(my-virtualenv) 20:00 ~ $ pip install xgboost Looking in links: /usr/share/pip-wheels Requirement already satisfied: xgboost in ./.virtualenvs/my-virtualenv/lib/python3.6/site-packages (0.80) Requirement already satisfied: scipy in ./.virtualenvs/my-virtualenv/lib/python3.6/site-packages (from xgboost) (1.1.0) Requirement already satisfied: numpy in ./.virtualenvs/my-virtualenv/lib/python3.6/site-packages (from xgboost) (1.14.5) (my-virtualenv) 20:00 ~ $

What do I have to do?

Thanks

M

Are you running the import with the virtualenv activated?

I have a shebang that did the trick for all previous installed modules:

!/home/ehlersanalytics/.virtualenvs/my-virtualenv/bin/python3.6

Then I import:

from flask import Flask

from flask import request

from flask import jsonify

import numpy as np

import pandas as pd

import pickle

import os

import xgboost

The strange thing is, if I import the xgb-model locally, I am not required to import xgboost at all since all information is contained in the imported object. At least so it appears, maybe I am mistaken. But if that is the case, why does my flask app fail when I import the model there?

Is your flask app using the virtualenv?

I would assume, otherwise it would drop an error on say numpy and pandas earlier, right? But how could I check if the flask app is using the virtualenv?

Ok, I selected the virtual-env additionally on the web tab (didn't know about this before) and now it works! So far the shebang was enough or at least I thought so. Thanks a lot for your help glenn!

Glad you worked it out!

The shebang only applies when you run a script from a console -- not when it's run as a web server -- which is why you need to use the input on the "Web" page that you found.