1
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using IronPython.Hosting;
    using Microsoft.Scripting.Hosting;

    namespace ConsoleApp1
    {
        class Program
        {
            static void Main(string[] args)
            {
                var var1 = 0;
                var var2 = 0;
                ScriptEngine engine = Python.CreateEngine();
                ScriptScope scope = engine.CreateScope();
                var searchPaths = engine.GetSearchPaths();
                searchPaths.Add(@"C:\Users\humay\AppData\Local\Programs\Python\Python310");
                engine.ExecuteFile(@"C:\Users\humay\Downloads\python.py", scope);
                dynamic testFunction = scope.GetVariable("test_func");
                var result = testFunction(var1, var2);
            }
        }
    }```

**Python**
import pandas as pd
from sklearn.naive_bayes import GaussianNB
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score, confusion_matrix
from sklearn.preprocessing import StandardScaler

def test_func(var1, var2):
    dataset = pd.read_csv('iris.csv')
    X = dataset.drop(columns=['Species'])
    y = dataset['Species']
    X_train, X_test, y_train, y_test = train_test_split(X,y, test_size =0.2)

    sc = StandardScaler()
    X_train = sc.fit_transform(X_train)
    X_test = sc.fit_transform(X_test)

    classifier = GaussianNB()
    classifier.fit(X_train, y_train)

    y_pred = classifier.predict(X_test)

    print(y_pred)

# cm = confusion_matrix(y_test, y_pred)
# ac = accuracy_score(y_test, y_pred)```

When I run the c# code, I get the error :"No module named pandas". I have ran "pip install pandas" and its still not working. I am trying to write bayesian classifier python code and run it in my project in asp.net

2
  • It's not uncommon to have multiple Python installations. You should run python -m pip install pandas, so you get the same interpreter. Commented Nov 13, 2021 at 0:53
  • Try this answer: stackoverflow.com/a/18433915/17242583 Commented Nov 13, 2021 at 1:03

1 Answer 1

1

You may be inside a virtual environment. To check, try running: which pip The response will vary depending on your OS.

/Users/.../venv/bin/pip

If the response contains venv then use the full path as pip i.e.

/Users/.../venv/bin/pip install pandas
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.