why this is not working, I have already installed sklearn. it is showing the error when I'm trying to execute it

Question:

Why this is not working, I have already installed sklearn.
I’m trying to create api for a ML model but getting so many errors in doing so . if anyone has done this please help me out.
I am using POSTMAN for sending html request but I’m not even able to create the API.

from flask import Flask, request, jsonify
import pickle
import numpy as np
app = Flask(__name__)
model=pickle.load(open('model.pkl','rb'))
@app.route('/')
def home():
    return "Hello world"


@app.route('/predict', methods=['GET', 'POST'])
def predict():
    cgpa = request.form.get('cgpa')
    iq = request.form.get('iq')
    profile_score = request.form.get('profile_score')
  #  result = {'cgpa': cgpa, 'iq': iq, 'profile_score': profile_score}
    input_query = np.array([[cgpa, iq, profile_score]])
    result = model.predict(input_query)[0]
    return jsonify({'placement': str(result)})


if __name__ == '__main__':
    app.run()
    


I'm getting this output : 

FLASK_APP = app.py
FLASK_ENV = development
FLASK_DEBUG = 0
In folder C:/Users/rohit/PycharmProjects/PlacePredictor
C:UsersrohitPycharmProjectsPlacePredictorvenvScriptspython.exe -m flask run 
Usage: python -m flask run [OPTIONS]
Try 'python -m flask run --help' for help.

Error: While importing 'app', an ImportError was raised:

Traceback (most recent call last):
  File "C:UsersrohitPycharmProjectsPlacePredictorvenvLibsite-packagesflaskcli.py", line 218, in locate_app
    __import__(module_name)
  File "C:UsersrohitPycharmProjectsPlacePredictorapp.py", line 5, in <module>
    model=pickle.load(open('model.pkl','rb'))
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ModuleNotFoundError: No module named 'sklearn'


Process finished with exit code 2```
Asked By: Rohit Prajapati

||

Answers:

Add import statement for sklearn in the flask file. You are unpickling a sklearn model but the flask package doesnot know sklearn therefore you also have to add import sklearn to the import section

Answered By: Shivam Singh