Can’t install imports in VsCode using ‘pip install’ and extra python extensions

I am trying to make a machine learning computer that you enter a math problem and say if the answer is right or not. But when I run it the terminal says…

File "******** - **Vs CodePythonmath.py", line 2, in <module>
    from sklearn.feature_extraction.text import CountVectorizer
ModuleNotFoundError: No module named 'sklearn'

This is just for the sklearn. There is also sympy.

This is my code. The bolded code is where the errors are.

import os
import pickle
from ***sklearn.feature_extraction.text*** import CountVectorizer
from ***sklearn.naive_bayes*** import MultinomialNB
from ***sympy*** import solve, symbols

DATA_FILE = "equations_data.pkl"

# Function to convert equations into features
def equation_to_features(equations):
    vectorizer = CountVectorizer()
    X = vectorizer.fit_transform(equations)
    return X

# Function to train the machine learning model
def train_model(equations, labels):
    X = equation_to_features(equations)
    clf = MultinomialNB()
    clf.fit(X, labels)
    return clf

# Function to predict solutions for equations
def predict_solution(equations, clf):
    X_test = equation_to_features(equations)
    predictions = clf.predict(X_test)
    return predictions

# Function to solve equations using SymPy
def solve_equations(equations):
    solutions = []
    x = symbols('x')
    for eq in equations:
        try:
            solution = solve(eq, x)
            solutions.append(solution[0] if solution else None)
        except:
            solutions.append(None)
    return solutions

# Function to load data from file
def load_data():
    if os.path.exists(DATA_FILE):
        with open(DATA_FILE, "rb") as f:
            return pickle.load(f)
    return [], []

# Function to save data to file
def save_data(equations, labels):
    with open(DATA_FILE, "wb") as f:
        pickle.dump((equations, labels), f)

# Main function
def main():
    equations, solutions = load_data()

    while True:
        # Ask for an equation
        equation = input("Enter an equation (e.g., '2*x + 3 = 7') or type 'exit' to quit: ")
        if equation.lower() == 'exit':
            break
        
        # Add equation to the list
        equations.append(equation)

        # Ask if the solution provided by the model is correct
        answer = input("Is the solution correct? (y/n): ")
        if answer.lower() == 'y':
            solutions.append(1)
        else:
            solutions.append(0)

        # Save data to file
        save_data(equations, solutions)

    # Train the model
    clf = train_model(equations, solutions)

    while True:
        # Ask for an equation
        equation = input("Enter an equation (e.g., '2*x + 3 = 7'): ")
        if equation.lower() == 'exit':
            break
        
        # Predict solution
        predicted_solution = predict_solution([equation], clf)[0]

        # Solve the equation using SymPy
        sym_solution = solve_equations([equation])[0]

        if sym_solution is not None:
            print("SymPy solution:", sym_solution)

        if predicted_solution is not None:
            print("Predicted solution:", predicted_solution)

        if predicted_solution is not None and sym_solution is not None:
            answer = input("Is the solution correct? (y/n): ")
            if answer.lower() == 'y':
                print("Great!")
                # Add equation and correctness to the training data
                equations.append(equation)
                solutions.append(1)
                clf = train_model(equations, solutions)
                # Save data to file
                save_data(equations, solutions)
            else:
                print("Oops! Let me learn from that.")
                # Add equation and correctness to the training data
                equations.append(equation)
                solutions.append(0)
                clf = train_model(equations, solutions)
                # Save data to file
                save_data(equations, solutions)
        else:
            print("Couldn't solve the equation.")

if __name__ == "__main__":
    main()

I tried installing extra extensions in VsCode but it didn’t work. I tried looking at other qustions in stack overflow but none of them answer the question I have. Please help.

New contributor

aCoder71641289479121 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật