Hi, i´am trying run a python code through a call in c#, but I need to import some packages and when I run the code the following message is displayed:
Missing required dependencies ['numpy', 'pytz']'.
I need these packages: numpy, pandas, collections and sklearn
This is my C# code:
private void button1_Click(object sender, EventArgs e)
{
Thread myThread = new Thread(new ThreadStart(startPy));
myThread.Start();
}
public static void startPy()
{
string filename = "Scripts\\Program.py";
string path = Assembly.GetExecutingAssembly().Location;
string rootDir = Directory.GetParent(path).FullName;
RunPythonFile(rootDir, filename);
}
public static int RunPythonFile(string rootDir, string filename)
{
ScriptEngine engine = Python.CreateEngine();
ScriptSource source;
source = engine.CreateScriptSourceFromFile(rootDir + "\\" + filename);
ScriptScope scope = engine.CreateScope();
int result = source.ExecuteProgram();
return result;
}
I have a button and this button call a thread that call my Python code which is in a folder called Script in the "bin / debug" path of the visual studio project
This is a part of my Python Code:
<pre>import clr
import sys
import time
clr.AddReference("System")
clr.AddReference("System.Windows.Forms")
clr.AddReference("System.Drawing")
clr.AddReference('IronPython')
from System.Windows.Forms import Application, Form, Button, Panel
from System.Drawing import Size
from IronPython.Compiler import CallTarget0
sys.path.append("C:\\Users\\Matheush\\AppData\\Local\\Programs\\Python\\Python37-32\\DLLs")
sys.path.append("C:\\Users\\Matheush\\AppData\\Local\\Programs\\Python\\Python37-32")
sys.path.append("C:\\Users\\Matheush\\AppData\\Local\\Programs\\Python\\Python37-32\\Lib\\site-packages")
import pandas as pd
from collections import Counter
import numpy as np
When it arrives in the part of the imports it presents that error message: <
Missing required dependencies ['numpy', 'pytz']'
How do I import these dependencies into visual studio?
Can someone help me please? Thank you
What I have tried:
I already tried to install the numpy and the other packages again, but it did not work. I tried to use the python distribution of anaconda3, but it also did not work.
In the PyCharm IDE of python the code works, but when I try to execute it by calling it from C # it presents this error in dependencies