我想在C#console应用程序python脚本中运行,其中包含numy、pandas、matplotlib.pyplot等库。如果我运行simple print('hello world')并将其保存为test.py,它就会工作
我添加到路径:D:\ProgramData\Anaconda3\Library\bin,但它对我也没有帮助。谢谢你试着帮助我
代码:
// 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);
您说过,当您使用Python运行脚本时,它可以工作。您是在运行环境之前首先创建环境的吗?这可能就是为什么从C#运行它时它不工作的原因
相关问题 更多 >
编程相关推荐