ModuleNotFoundError: No module named 'sklearn'

Hi Dear I am having an issue trying to deploy my machine learning model built using pythonShell and NodeJs. Here are a screenshot of the code

This is a code fragment on how I created the API endpoint and plugged it into my NodeJs.

in my index.js file, I wrote this code
app.post(“/api/Jn_model”, function (req, res) {

const description = req.body.description;

const options = {

    args: description
}

PythonShell.run('python-code/jn_model.py', options)

.then(messages => {
    console.log(messages)
    res.json(
        {
            "predictions": messages
        }
    );
});

});

In my python-code/jn_model.py, I am calling my saved pickle model
import pickle
import sys

with open(‘models/ababoost_Jn.pkl’,‘rb’) as f:
Jn_model = pickle.load(f)
pred = Jn_model.predict([[sys.argv[1]]])
print(pred)

In my AlpineJs file where I am making use of alpine, this is how I am sending it to my frontend index.html
axios
.post(“/api/Jn_model”, {
description: parseInt(this.value_Jn),
})
.then((res) => {
let val = res.data.predictions[0];
val = val.split(“[”)[1];
val = val.split(“]”)[0];
console.log(res.data);
this.JnVal =
"Based on your input, the predicted Jn value is " +
val;
// this.getRecord();
});
setTimeout(() => (this.JnVal = “”), 30000);
},

All the variables for the alpineJs have been declared and locally it is working perfectly well. I created a requirements.txt (which contains scikit-learn and every other possible requirements) file and pip install requirements.txt in my package.json to tell render to install the requirements.

After pushing to github and connect on render, I keep getting this error

“ModuleNotFoundError: No module named ‘sklearn’\n”,
executable: ‘python3’,
options: null,

Please if anyone has ever come across such an error, I would appreciate the help.

Hi Fabchi,

I’ll respond to the ticket you opened on this topic as well. Lets continue the discussion there to avoid confusing duplicate threads.

Regards,

Matt

I have the same problem. What to do?

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.