C# 中的 IronPython:没有名为 xmlrpclib 的模块

发布于 2024-09-25 07:54:41 字数 702 浏览 1 评论 0原文

我正在尝试为 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

迷鸟归林 2024-10-02 07:54:41

抱歉问了这个愚蠢的问题,事实证明 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文