C# 中的 IronPython:没有名为 xmlrpclib 的模块
我正在尝试为 IronPython 构建一个带有交互式控制台的 Web 应用程序。当我尝试在 IronPython 的普通控制台中导入 xmlrpclib 时,它可以工作。但是,如果我在 C# 代码中使用 IronPython,它会引发异常“No module named xmlrpclib”。这是一个已知问题吗?有什么解决方案可以解决这个问题吗?
这是代码:
var testCode = @"
import xmlrpclib;
APIServer = xmlrpclib.ServerProxy('address', allow_none=True);
print APIServer.Hello();
";
MyStream str = new MyStream();
ScriptEngine engine = Python.CreateEngine();
engine.Runtime.IO.SetOutput(str, System.Text.Encoding.ASCII);
engine.Runtime.IO.SetErrorOutput(str, System.Text.Encoding.ASCII);
ScriptScope scope = engine.CreateScope();
ScriptSource src = engine.CreateScriptSourceFromString(testCode);
src.Execute(scope);
I am trying to build a web application with an interactive console for IronPython. When I try to import xmlrpclib in IronPython's normal console, it works. However, if I use IronPython inside my C# code, it throws an exception "No module named xmlrpclib". Is this a known issue? Any solutions to solve this issue?
Here's the code:
var testCode = @"
import xmlrpclib;
APIServer = xmlrpclib.ServerProxy('address', allow_none=True);
print APIServer.Hello();
";
MyStream str = new MyStream();
ScriptEngine engine = Python.CreateEngine();
engine.Runtime.IO.SetOutput(str, System.Text.Encoding.ASCII);
engine.Runtime.IO.SetErrorOutput(str, System.Text.Encoding.ASCII);
ScriptScope scope = engine.CreateScope();
ScriptSource src = engine.CreateScriptSourceFromString(testCode);
src.Execute(scope);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
抱歉问了这个愚蠢的问题,事实证明 IronPython 在我的 C# 代码中使用的路径不正确。我刚刚纠正了路径,一切正常。感谢挖掘EmAll。
Sorry for the silly question, it turned out that the path used by IronPython inside my C# code was not correct. I just corrected the path, and everything works fine. Thanks to digEmAll.