从c#调用python脚本,意外标记';从';错误
尝试在VisualStudio中开始使用IronPython。创建了一个C#winforms应用程序来运行python脚本。从“错误”获取“意外令牌”。python脚本包含一行代码:从c#调用python脚本,意外标记';从';错误,c#,python,C#,Python,尝试在VisualStudio中开始使用IronPython。创建了一个C#winforms应用程序来运行python脚本。从“错误”获取“意外令牌”。python脚本包含一行代码: import numpy as np 就这样。我不能理解这个错误。我尝试了一个print语句,但是任何导入都会抛出“from”错误 以下是C#代码: var py=Python.CreateEngine(); 字符串main=; String dir=String.Empty; ICollection path=
import numpy as np
就这样。我不能理解这个错误。我尝试了一个print语句,但是任何导入都会抛出“from”错误
以下是C#代码:
var py=Python.CreateEngine();
字符串main=;
String dir=String.Empty;
ICollection path=py.getSearchPath();
添加路径(dir);
dir=main+@“\Lib\site packages”;
添加路径(dir);
dir=main+@“\Lib”;
添加路径(dir);
设置搜索路径(路径);
py.ExecuteFile(“Test.py”);
MessageBox.Show(“完成”);
有人知道发生了什么吗 Python库之间的不兼容。如果两个库都有,请确保引用正确的库。Python库之间的不兼容性。如果两者都有,一定要引用正确的一个。结果是Python 2和Anaconda 3之间不兼容。使用了正确的库(Anaconda 2),但出现了不同的错误。显然,numpy和IronPython存在一些问题,但这不是问题所在。事实证明,这是Python 2和Anaconda 3之间的不兼容。使用了正确的库(Anaconda 2),但出现了不同的错误。显然,numpy和IronPython存在问题,但这不是问题所在。
var py = Python.CreateEngine();
String main = <my anaconda3 directory> ;
String dir = String.Empty;
ICollection<String> paths = py.GetSearchPaths();
paths.Add(dir);
dir = main + @"\Lib\site-packages";
paths.Add(dir);
dir = main + @"\Lib";
paths.Add(dir);
py.SetSearchPaths(paths);
py.ExecuteFile("Test.py");
MessageBox.Show("Done");