我是C开发人员,必须在.NET框架中使用IronPython库。我测试了Python中的每一个类,它都在工作,但是我不知道如何在C类中调用库。在
当我试图调用库时,我得到一个'LightException' object has no attribute
客户端错误。在
我添加了lib、-x:Full frame和lib文件夹中的所有模块。在
下面是我用来调用Python库的C代码:
Console.WriteLine("Press enter to execute the python script!");
Console.ReadLine();
var options = new Dictionary<string, object>();
options["Frames"] = true;
options["FullFrames"] = true;
//var py = Python.CreateEngine(options);
//py.SetSearchPaths(paths);
ScriptEngine engine = Python.CreateEngine(options);
ICollection<string> paths = engine.GetSearchPaths();
string dir = @"C:\Python27\Lib\";
paths.Add(dir);
string dir2 = @"C:\Python27\Lib\site-packages\";
paths.Add(dir2);
engine.SetSearchPaths(paths);
ScriptSource source = engine.CreateScriptSourceFromFile(@"C:\Users\nikunjmange\Source\Workspaces\Visage Payroll\VisagePayrollSystem\VisagePayrollSystem\synapsepayLib\synapse_pay-python-master\synapse_pay\resources\user.py");
ScriptScope scope = engine.CreateScope();
source.Execute(scope);
dynamic Calculator = scope.GetVariable("User");
dynamic calc = Calculator();
string inputCreate = "nik12@gmail.com";
string result = calc.create(inputCreate);
错误误导because of a bug in IronPython 2.7.5。它应该是
ImportError
。不要添加普通的cpythonstdlib;它与IronPython不兼容。改用IronPython的stdlib。
如果您有一个
import a.b as c
的导入,这可能就是罪魁祸首;a或b不存在,但IronPython会破坏错误报告。在相关问题 更多 >
编程相关推荐