我正在尝试用IronPython在.NET 4.0上使用IronPython 2.7来执行这个方法。我正在使用Windows 7
import os
import re
import nltk
import urllib
import xapian
import sys
def getData(url):
try:
html = urllib.urlopen(url)
text = html.read()
html.close()
except:
return "error"
try:
return nltk.clean_html(text) #takes the tokens
except:
return textC#代码:
public static object Execute()
{
string scriptPath = "Calculator.py";
ScriptEngine engine = Python.CreateEngine();
engine.SetSearchPaths(new string[] { "c:\\Python26\\lib","c:\\Python26\\lib\\site-packages",
"C:\\IronPython-2.7\\Lib\\site-packages","C:\\IronPython-2.7\\Lib"});
ScriptSource source = engine.CreateScriptSourceFromFile(scriptPath);
ScriptScope scope = engine.CreateScope();
ObjectOperations op = engine.Operations;
source.Execute(scope);
dynamic Calculator = scope.GetVariable("Calculator");
dynamic calc = Calculator();
return calc.getData("http://www.wowebook.com/dot-net/ironpython-in-action.html");
}谁能告诉我我哪里做错了?我一直在说我没有fcntl模块。
发布于 2011-04-05 03:55:42
我认为到目前为止,您最简单的解决方案是切换到CPython。我不认为它会比你现有的解决方案的集成度低,而且你可以避免缺少模块带来的所有麻烦。
发布于 2011-04-05 03:28:52
the following StackOverflow thread是windows原生平台( isn't really:Unix),所以你可能不太走运,fcntl可能(也可能不)会有帮助……
发布于 2013-04-20 00:01:48
当我遇到这个问题时,问题是我只在搜索路径中有我的CPython库(我之前在CPython中安装了NLTK库),而没有IronPython库。
在我的C#代码中,我现在有类似这样的东西
engine.SetSearchPaths(new string[] {"C:\\Program Files\\IronPython 2.7\\Lib"
,"C:\\Python27\\Lib"
,"C:\\Python27\\Lib\\site-packages"
});当我在这个问题上挠头时,我注意到我意外地输入了2.7.1作为我的IronPython路径,即。不存在的目录。哦,我刚刚注意到OP在他们的源代码中有一个类似的搜索路径条目,也许也可能是搜索路径的顺序?
对于处于类似位置的人有用的提示:我注意到我的使用NLTK的代码在从ipy.exe加载它时工作得很好,所以不存在像…这样的可移植性问题。(并且NLTK source不包含字符串fcntl anywhere)
https://stackoverflow.com/questions/5543229
复制相似问题