ImportError with IronPython in C#
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:
- 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.
ImportError with IronPython in C#的更多相关文章
- IronPython .NET Integration官方文档翻译笔记
http://ironpython.net/documentation/dotnet/这是原文地址 以下笔记仅记录阅读过程中我认为有必要记录的内容,大多数都是依赖翻译软件的机翻,配合个人对代码的理解写 ...
- ImportError: No module named 'requests'
补充说明: 当前环境是在windows环境下 python版本是:python 3.4. 刚开始学习python,一边看书一边论坛里阅读感兴趣的代码, http://www.oschina.net/c ...
- 跨语言和跨编译器的那些坑(CPython vs IronPython)
代码是宝贵的,世界上最郁闷的事情,便是写好的代码,还要在另外的平台上重写一次,或是同时维护功能相同的两套代码.所以才需要跨平台. 不仅如此,比如有人会吐槽Python的原生解释器CPython跑得太慢 ...
- python3中用HTMLTestRunner.py报ImportError: No module named 'StringIO'如何解决
python3中用HTMLTestRunner.py报ImportError: No module named 'StringIO'的解决方法: 1.原因是官网的是python2语法写的,看官手动把官 ...
- ImportError: The _imagingft C module is not installed
添加验证码模块的时候,发布到服务器上居然报了这个错误 ImportError: The _imagingft C module is not installed 然而pillow是已经装在服务器上的, ...
- ImportError: cannot import name 'check_arrays'
from sklearn.utils.validation import check_arrays 执行 from sklearn.utils.validation import check_arra ...
- Ubuntu: ImportError: No module named xgboost
ImportError: No module named xgboost 解决办法: git clone --recursive https://github.com/dmlc/xgboost cd ...
- [搬砖]Pycharm中启动IPython notebook失败提示load_entry_point ImportError: Entry point ('console_scripts', 'ipython') not found的解决方法
前提:直接运行ipython正常,“which -a ipython”命令显示也只有一个ipython存在,在ipynb文件中点运行启动notebook时提示错误类似如下: Traceback (mo ...
- gdb 调试出现 ImportError: No module named 'libstdcxx'
在emacs使用gdb调试程序,出现错误 , in <module> from libstdcxx.v6.printers import register_libstdcxx_printe ...
随机推荐
- PAT 1055
题目链接:https://www.patest.cn/contests/pat-b-practise/1055 分析:思路很巧妙,感觉很有意义的字符串题目 #include<bits/stdc+ ...
- Webbrowser控件execcommand参数详解
2D-Position 允许通过拖曳移动绝对定位的对象.AbsolutePosition 设定元素的 position 属性为“absolute”(绝对).BackColor 设置或获取当前选中区的背 ...
- [翻译]利用C#获取终端服务(Terminal Services)会话的闲置时间
[翻译]利用C#获取终端服务(Terminal Services)会话的闲置时间 作者:Tuuzed(土仔) 发表于:2008年2月29日版权声明:可以任意转载,转载时请务必以超链接形式标明文章原 ...
- newlisp 注释生成文档
最近写了一个newlisp_armory库,用来实现一些newlisp自身不支持的操作.比如跨windows和ubuntu的目录拷贝功能等. 自己用的时候,发现没有API reference文档参考, ...
- Centos 5.5 更新网卡驱动 bnx2 version: 2.0.2
操作系统:CentOS release 5.5 (Final) 故障现象:网卡无故自动down掉,使用service network restart 重启后没多久又会自动down , 连接数大概在2 ...
- 免费git服务器以及使用过程中遇到的问题
1. git rm *,git pull会先git fetch后再git merge,更安全的做法是git fetch修改后再push:git remote rm origin 2. https:// ...
- ubuntu配置jdk脚本以及导致开不了机的解决方案
关于在那个文件里配置jdk脚本,有些大牛总结了四个地方,大体就是ubuntu系统启动后会默认加载的四个地方.例如:/etcenvironment,/etc/profile这两个文件处于系统层面的,还有 ...
- jQuery拖动调整表格列宽度-resizableColumns
实现鼠标可拖动调整表格列宽度 如图: 一.引入文件: <script src="/js/jquery-1.8.0.min.js" type="text/javasc ...
- POJ 1838 Banana (并查集)
Description Consider a tropical forrest, represented as a matrix. The cell from the right top corner ...
- hibernate之关于使用连接表实现多对一关联映射
[Hibernate]之关于使用连接表实现多对一关联映射 在我们项目使用中採用中间表最多的一般就是多对一,或者是多对多,当然一对一使用中间表也是能够的,可是这样的几率通常少之又少!所以这里重点介绍多对 ...