• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

ImportErrorwithIronPythoninC#

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

I was using IronPython to execute python code inside my C# implementation lately, and I encountered this error when trying to use xmlrpclib:

  
    ImportError: No module named xmlrpclib.

It was really frustrating because if I try the same in IronPython console, it works fine. It turned out that this was a problem with search paths. When called via C# code, IronPython does not search for missing libraries unless you provide it a path to search for. Here’s how I solved this issue:

  1. First, find out the search paths that IronPython is using in console mode:
import sys
print sys.path

This will print all the search paths. Save these paths somewhere.

  1. Now include all these search paths inside your C# code:
ScriptEngine Engine = Python.CreateEngine();
ICollection<string> Paths = Engine.GetSearchPaths();
Paths.Add("<Path>");
Engine.SetSearchPaths(Paths);

Replace <Path> with the path you saved earlier. Now IronPython will search all these pathsbefore failing with an ImportError.


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C#创建ini文件并读写发布时间:2022-07-13
下一篇:
C#委托与事件的简单使用发布时间:2022-07-13
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap