如何在.NET中导入第三方IronPython模块?

2024-10-02 00:43:27 发布

您现在位置:Python中文网/ 问答频道 /正文

我是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);

Tags: pytruestringobjectvarlibdirengine
1条回答
网友
1楼 · 发布于 2024-10-02 00:43:27
  1. 错误误导because of a bug in IronPython 2.7.5。它应该是ImportError

  2. 不要添加普通的cpythonstdlib;它与IronPython不兼容。改用IronPython的stdlib。

如果您有一个import a.b as c的导入,这可能就是罪魁祸首;a或b不存在,但IronPython会破坏错误报告。在

相关问题 更多 >

    热门问题