我试图在C#中执行
python代码.通常它应该使用Iron
Python并在安装PTVS之后完成(我正在使用VS 2010).
var pyEngine = Python.CreateEngine(); var pyScope = pyEngine.CreateScope(); try { pyEngine.ExecuteFile("plot.py",pyScope); } catch (Exception ex) { Console.WriteLine("There is a problem in your Python code: " + ex.Message); }
问题是IronPython似乎无法识别像numpy,pylab或matplotlib这样的库.我看了一下,发现有些人在谈论Enthought Canopy或Anaconda,我已经安装了两个而没有解决问题.
我该怎么做才能解决问题?
解决方法
为了执行导入一些库(如numpy和pylab)的Python脚本,可以这样做:
string arg = string.Format(@"C:\Users\ayed\Desktop\IronPythonExamples\RunExternalScript\plot.py"); // Path to the Python code Process p = new Process(); p.StartInfo = new processstartinfo(@"D:\WinPython\WinPython-64bit-2.7.5.3\python-2.7.5.amd64\python.exe",arg); p.StartInfo.UseShellExecute = false; p.StartInfo.CreateNowindow = true; // Hide the command line window p.StartInfo.RedirectStandardOutput = false; p.StartInfo.RedirectStandardError = false; Process processChild = Process.Start(p.StartInfo);
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。