问题描述
我得到了IronPython的单声道工作正常,但它不会导入登录
模块。
执行这段代码:
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
的
我已经包括了IronPython的程序集都是最新的。IronPython.Modules.dll,Microsoft.Dynamic.dll,Microsoft.Scripting.dll,Microsoft.Scripting.Metadata.dll
The IronPython assemblies I have included are up-to-date: IronPython.Modules.dll, Microsoft.Dynamic.dll, Microsoft.Scripting.dll, Microsoft.Scripting.Metadata.dll.
我怎样才能使内IronPython的使用记录模块的?
How can I make use of the logging module within Ironpython?
推荐答案
这是不够的组件添加到您的C#应用。 登录
是用Python编写,它的标准库的一部分。你必须标准库添加到 IRONPYTHONPATH
为好。你可以做到这一点是这样的:
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);
如果你需要,你可能会需要你的应用程序出货的标准库。我的建议是压缩它,然后zip文件添加到路径
。
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
.
这篇关于IronPython的ImportException:无模块命名记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!