ImportError with IronPython in C#
2016-04-03 11:59
561 查看
I was using IronPython to execute python code inside my C# implementation lately, and I encountered this error when trying to use 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:
First, find out the search paths that IronPython is using in console mode:
This will print all the search paths. Save these paths somewhere.
Now include all these search paths inside your C# code:
Replace
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:
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.
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.
相关文章推荐
- 在C#环境中动态调用IronPython脚本(二)
- python笔记(持续更新)
- 在C#环境中动态调用IronPython脚本(一)
- Python Discuz 7.2 faq.php 注入漏洞全自动利用工具
- NumPy学习笔记
- NumPy学习笔记
- python导出函数方法
- leetcode @python 130. Surrounded Regions
- 自动化测试常用断言的使用方法(python)
- leetcode @python 129. Sum Root to Leaf Numbers
- leetcode @python 128. Longest Consecutive Sequence
- leetcode @python 127. Word Ladder
- python中的operator库
- 如何配置OPENCV的Python接口
- Python基础之数据类型
- java和python对比
- python的注释
- Python之路【第十八篇】Django小项目简单BBS论坛部分内容知识点
- python中的字符串
- python中yaml模块的使用