将带有ML的python脚本运行到C#控制台应用程序错误

2024-09-29 21:37:53 发布

您现在位置:Python中文网/ 问答频道 /正文

我想在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);

console error


Tags: pathpystringprocessexemlusersfull

热门问题