我是 C# 开发人员,我必须在 .NET 框架中使用 IronPython 库。我在 Python 中测试了每个类并且它正在工作,但我不确定如何在 C# 类中调用该库。
当我尝试调用库时,出现'LightException' object has no attribute
客户端错误。
我在 lib 文件夹中添加了 lib、-x:Full frame 以及所有模块。
这是我用来调用 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);