I am C# developer and I have to use an IronPython library in the .NET framework. I tested every class in Python and it's working but I am not sure how to call the library in a C# class.
我是C#开发人员,我必须在.NET框架中使用IronPython库。我在Python中测试了每一个类,它正在工作,但我不确定如何在C#类中调用库。
When I try to call the library, I am getting a 'LightException' object has no attribute
client error.
当我尝试调用库时,我得到一个'LightException'对象没有属性客户端错误。
I have added lib, -x:Full frame and also all modules in the lib folder.
我添加了lib,-x:全帧以及lib文件夹中的所有模块。
Here is the C# code I am using to call the Python library:
这是我用来调用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);
1 个解决方案
#1
2
-
The error is misleading because of a bug in IronPython 2.7.5. It should be an
ImportError
.由于IronPython 2.7.5中的错误,该错误具有误导性。它应该是一个ImportError。
-
Don't add the normal CPython stdlib; it's not compatible with IronPython. Use IronPython's stdlib instead.
不要添加正常的CPython stdlib;它与IronPython不兼容。请改用IronPython的stdlib。
If you have an import of import a.b as c
that's probably the culprit; either a or b does not exist but IronPython mucks up the error reporting.
如果您导入a.b导入为c,则可能是罪魁祸首; a或b不存在,但IronPython破坏了错误报告。
#1
2
-
The error is misleading because of a bug in IronPython 2.7.5. It should be an
ImportError
.由于IronPython 2.7.5中的错误,该错误具有误导性。它应该是一个ImportError。
-
Don't add the normal CPython stdlib; it's not compatible with IronPython. Use IronPython's stdlib instead.
不要添加正常的CPython stdlib;它与IronPython不兼容。请改用IronPython的stdlib。
If you have an import of import a.b as c
that's probably the culprit; either a or b does not exist but IronPython mucks up the error reporting.
如果您导入a.b导入为c,则可能是罪魁祸首; a或b不存在,但IronPython破坏了错误报告。