将带有ML的python脚本运行到C#控制台应用程序错误
我想在C#console应用程序python脚本中运行,其中包含numy、pandas、matplotlib.pyplot等库。如果我运行simple print('hello world')并将其保存为test.py,它就会工作 我添加到路径:D:\ProgramData\Anaconda3\Library\bin,但它对我也没有帮助。谢谢你试着帮助我 代码:将带有ML的python脚本运行到C#控制台应用程序错误,python,c#,Python,C#,我想在C#console应用程序python脚本中运行,其中包含numy、pandas、matplotlib.pyplot等库。如果我运行simple print('hello world')并将其保存为test.py,它就会工作 我添加到路径:D:\ProgramData\Anaconda3\Library\bin,但它对我也没有帮助。谢谢你试着帮助我 代码: 您说过,当您使用Python运行脚本时,它可以工作。您是在运行环境之前首先创建环境的吗?这可能就是为什么从C#运行时无法工作的原因。您
您说过,当您使用Python运行脚本时,它可以工作。您是在运行环境之前首先创建环境的吗?这可能就是为什么从C#运行时无法工作的原因。您是否尝试了控制台日志错误中提到的故障排除步骤?请务必让我们知道调试中的output.outputString=“”,在我为测试print(“hello”)而编写的python脚本中,与我的预测值不同,但它是相同的。我检查了控制台日志错误中的所有步骤,并尝试将其修复到许多示例中,但没有人使用import libraries Swell,我说,简单的python脚本在该代码中工作,但是当我想从python脚本中的ML模型中获取预测值时,它不起作用,因为存在导入库,并且存在一个问题。
// full path to .py file
string pyScriptPath = @"C:\Users\micha\Documents\ML\multipleLinearRegression\multiple_linear_regression.py";
string outputString = null;
// create new process start info
ProcessStartInfo prcStartInfo = new ProcessStartInfo
{
// full path of the Python interpreter 'python.exe'
FileName = @"D:\ProgramData\Anaconda3\python.exe", // string.Format(@"""{0}""", "python.exe"),
UseShellExecute = false,
RedirectStandardOutput = true,
CreateNoWindow = false,
Arguments = @"C:\Users\micha\Documents\ML\multipleLinearRegression\multiple_linear_regression.py"
};
// start process
using (Process process = Process.Start(prcStartInfo))
{
// read standard output JSON string
using (StreamReader myStreamReader = process.StandardOutput)
{
outputString = myStreamReader.ReadLine();
process.WaitForExit();
}
}
Console.WriteLine(outputString);