IronPython ImportException: No module named logging

雨燕双飞 提交于 2020-01-11 03:06:10

问题


I got ironpython working fine on mono, but it doesn't import the logging module. Executing this code:

ScriptEngine engine = Python.CreateEngine();
dynamic logging = engine.ImportModule("logging");

yields the following error:

IronPython.Runtime.Exceptions.ImportException: No module named logging

The IronPython assemblies I have included are up-to-date: IronPython.Modules.dll, Microsoft.Dynamic.dll, Microsoft.Scripting.dll, Microsoft.Scripting.Metadata.dll.

How can I make use of the logging module within Ironpython?


回答1:


It's not enough to add the assemblies to your C# application. logging is written in python, and it's part of the standard library. You'll have to add the standard library to IRONPYTHONPATH as well. You can do it like this:

var engine = Python.CreateEngine();
var paths = engine.GetSearchPaths();
paths.Add(@"C:\Path\to\your\standard\library");
engine.SetSearchPaths(paths);

If you need the standard library you would probably need to ship it with your application. My suggestion is to zip it and then add the zip file to the paths.



来源:https://stackoverflow.com/questions/18975311/ironpython-importexception-no-module-named-logging

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!