IronPython如何在托管时加载模块?
我对IronPython在托管时加载模块的方式感到困惑 我使用的是使用MSI软件包安装的IronPython 2.7.7,我引用了IronPython如何在托管时加载模块?,python,.net,ironpython,Python,.net,Ironpython,我对IronPython在托管时加载模块的方式感到困惑 我使用的是使用MSI软件包安装的IronPython 2.7.7,我引用了C:\Program Files(x86)\IronPython 2.7\IronPython.dll和C:\Program Files(x86)\IronPython 2.7\Microsoft.Scripting.dll 有时IronPython加载模块失败,抛出IronPython.Runtime.Exceptions.ImportException:“没有名为
C:\Program Files(x86)\IronPython 2.7\IronPython.dll
和C:\Program Files(x86)\IronPython 2.7\Microsoft.Scripting.dll
有时IronPython加载模块失败,抛出IronPython.Runtime.Exceptions.ImportException:“没有名为modulename的模块”
,但有时一切正常
比如说,
var engine = Python.CreateEngine();
engine.CreateScriptSourceFromString("import datetime; print datetime.datetime.now()").Execute();
有效,但是
var engine = Python.CreateEngine();
engine.CreateScriptSourceFromString("import json; print json.dumps(['foo', {'bar': ('baz', None, 1.0, 2)}])").Execute();
没有
我发现了一个在引擎中设置搜索路径的建议。所以我加了一句
var searchPaths = engine.GetSearchPaths();
searchPaths.Add(@"C:\Program Files (x86)\IronPython 2.7\Lib");
engine.SetSearchPaths(searchPaths);
现在,使用json
模块的示例开始工作
但是我从引擎获取的搜索路径只包含
“
“D:\\IronPythonTest\\bin\\Debug\\Lib”
“D:\\IronPythonTest\\bin\\Debug\\DLLs”
我的Debug
文件夹下既没有Lib
也没有DLLs
文件夹
那么IronPython是如何加载datetime
模块的呢
提前感谢您的澄清。您向引擎添加相关路径的基本方法是正确的
IronPython使用大量的标准库(只要可能)。在CPython中本机实现的低级模块在IronPython的C#中实现。其中之一就是。因此,只要存在IronPython.Modules.dll
,即使没有特定的加载/路径处理,也可以使用几个标准模块