IronPython 设置包路径
C#中添加对python文件或者对python包的引用时出现"no module .."的问题时的解决办法。

对hello.py 做一些简单的修改
添加
import syssys.path.append(<DIR>)
因为我的hashlib在该目录"D:\IronPython2.7\Lib"下,<DIR>为"D:\IronPython2.7\Lib

////
def load_config(keyword_category, config_path = r'./config'):
#load keywords under designated category from config file
###INPUT: str keyword_category -> also serves as name of config file; _
#str config_path -> location of config files
###OUTPUT: list result -> keywords loaded from config file
import os.path
config_file = os.path.join(config_path, keyword_category+'.txt')
f = read(config_file, 'r')
result = []
for line in f:
result.append(line.replace('\n','').decode('utf8'))
f.close()
return result
在C#这一端,调用代码如下(项目已经添加引用ironpython.dll, ironpython.hosting.dll, microsoft):
public string[] GetKeywords(string category, string config_path)
{ ScriptRuntime pyRunTime = Python.CreateRuntime();
dynamic pyScript = pyRunTime.UseFile(@".\python scripts\file_utils.py"); List<string> tmp = pyScript.load_config(category, config_path);
tmp.TrimExcess(); string[] result = tmp.ToArray(); return result;
}
运行时VS2013反馈的错误信息如下:
An unhandled exception of type 'IronPython.Runtime.Exceptions.ImportException' occurred in Microsoft.Dynamic.dll
Additional information: No module named os.path
很奇怪的一点是,其他python代码里引用os等标准库完全没有问题,不知道为什么惟独os.path会出现问题
IronPython 设置包路径的更多相关文章
- python 设置默认的导包路径
在python中 可以通过 sys 模块添加导包时的搜寻路径, sys.path 返回的是所有默认导包路径的列表(搜索次序从下标为零开始,直到寻找到需要导入的包结束) sys.path.insert( ...
- YourSQLDba设置共享路径备份
YourSQLDba可以将数据库备份到网络路径(共享路径),这个也是非常灵活的一个功能,以前一直没有使用过这个功能,最近由于一个需求,于是我测试了一下YourSQLDba备份到网络路径,中间遇到了一些 ...
- 详细解说Tomcat 设置虚拟路径的几种方法及为什么设置虚拟路径
说明:此次使用的是Tomcat 7.0 很多朋友都会很疑惑,既然我们都知道在Tomcat服务器上部署项目只要将项目打包,然后放到webapps目录下就可以了,为什么还需要配置虚拟路径?的确,把项目放到 ...
- InstallShield打包设置相对路径
InstallShield打包设置相对路径 在使用Installshield 打包安装文件时,添加打包文件时默认使用绝对路径,但是工程文件转移时(复制到其它位置时)编译时就会找不到安装文件,这样很不方 ...
- android adt自带eclipse无法设置ndk路径(找不到NDK配置)
分步阅读 到android sdk官网下载r23版本的adt时自带的eclipse没有设置ndk路径的地方,通过Install New Software 发现无法更新,那么如何解决这个问题呢? 方便他 ...
- skyline TerraExplorer fly设置相对路径的方法
软件环境:TerraExplorer Pro(以下简称TEP)6.5 在TEP中,对于本地(非网络)文件路径,默认都是绝对路径,在移动数据时非常麻烦,以下是本人总结出一些设置相对路径的规则 假设fly ...
- 通过扫描包路径获取包内class
public static Set<Class<?>> getClasses(ClassLoader classLoader, String pack) { Set<Cl ...
- Eclipse无法设置NDK路径的解决方法
如果在Eclipse中设置NDK路径的时候遇到下面的情况(尼玛,我的NDK设置呢?): 可以参考百度经验解决:http://jingyan.baidu.com/article/4d58d5413000 ...
- WAS下获取包路径下所有类
最近做javaweb项目的混淆工作,用到proguard,该工具混淆.jar文件比较方便,故把所有项目代码和配置文件打成jar包, 生成的jar包经过proguard处理后,再次打包(解决progua ...
随机推荐
- Java Debugging
1, https://visualvm.java.net/oqlhelp.html#top http://docs.oracle.com/javase/7/docs/technotes/samples ...
- ascii codec can't decode byte 0xe8 in position 0:ordinal not in range(128)
问题描述:一个在Django框架下使用Python编写的定时更新项目,在一个Linux系统下运行没有问题,在另外一台Linux系统下测试,报如下错误: ascii codec can't decode ...
- lucene 索引流程整理笔记
索引的原文档(Document). 为了方便说明索引创建过程,这里特意用两个文件为例: 文件一:Students should be allowed to go out with their frie ...
- Linux进程间通信-命名管道
前面我们讲了进程间通信的一种方式,匿名管道.我们知道,匿名管道只能用于父子关系的进程之间.那么没有这种关系的进程之间该如何进行数据传递呢? 1.什么是命名管道 匿名管道是在缓存中开辟的输出和输入文件流 ...
- 使用git提交github代码
新的项目的提交 touch README.md git init git add README.md git commit -m "first commit" git remote ...
- 二十四种设计模式:原型模式(Prototype Pattern)
原型模式(Prototype Pattern) 介绍用原型实例指定创建对象的种类,并且通过拷贝这个原型来创建新的对象.示例有一个Message实体类,现在要克隆它. MessageModel usin ...
- MySQL数据库update更新子查询
比如: ? 1 2 3 4 UPDATE test.tb_vobile a set a.name = '111 ' WHERE a.id = (select max(id) id from test. ...
- Oracle中replace函数的使用
例: select filefullname from sys_frmattachmentdb 查询的结果为: e:\GengBaoFile\TYGW\<历城区项目立项审批流程>.1079 ...
- 日期转换类 DateConverter.java
package com.util; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.D ...
- 【linux】CentOS安装mysql*.rpm提示conflicts with file from package的解决办法
使用以下命令安装: rpm -ivh MySQL-server-5.6.19-1.linux_glibc2.5.x86_64.rpm 错误提示如下: Preparing... ...