没有名为 fcntl 的模块
我正在尝试使用 IronPython 2.7 在 .NET 4.0 上使用 IronPython 执行此方法。我正在使用 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 text
C# 代码:
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 模块
I am trying to execute this method with IronPython on .NET 4.0 using IronPython 2.7. i am using 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 text
C# CODE:
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");
}
Can someone tell me what I am doing wrong? I keep gettin that i do not have fcntl module
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
fcntl 实际上并不是 Windows 本机(平台:Unix),所以你可能会出局幸运的是,以下 StackOverflow 线程可能(或可能没有)有帮助...
fcntl isn't really a windows native (platform: Unix) so you might be out of luck, the following StackOverflow thread might (or might not) be helpful...
当我遇到这个问题时,问题是我的搜索路径中只有我的 CPython 库(我之前在 CPython 中安装了 NLTK),而不是 IronPython 的库。
在我的 C# 代码中,我现在有类似的内容
当我为这个确切的问题抓耳挠腮时,我注意到我不小心输入了 2.7.1 作为我的 IronPython 路径,即。不存在的目录。哦,我刚刚注意到OP在他们的源代码中有一个类似的搜索路径条目,也许也可能是搜索路径的顺序?
对于处于类似职位的人来说有用的线索:我注意到我的 NLTK 使用代码在从 ipy.exe 加载时工作得很好,所以不是可移植性问题……(并且 NLTK 源代码在任何地方都不包含字符串 fcntl)
When I ran into this, the problem turned out to be that I only had my CPython libs in the search path (I had previously installed NLTK in CPython) and not the IronPython ones.
In my C# code, I now have something like
When scratching my head over this exact issue, I noticed I had accidentally entered 2.7.1 as my IronPython path, ie. a non-existing directory. Oh, I just noticed OP has a similar search path entry in their source, perhaps also could be order of search path?
Useful clue for people in similar positions: I noticed that my NLTK-using code worked just fine when loading it from ipy.exe, so not a portability issue as such… (and NLTK source does not contain the string fcntl anywhere)
我认为到目前为止最简单的解决方案是切换到 CPython。我认为它的集成度不会比您现有的解决方案低,并且您可以避免因缺少模块而带来的所有麻烦。
I think by far your easiest solution would be to switch to CPython. I don't think it would be any less integrated than your existing solution and you'd avoid all the headaches with missing modules.
遇到了完全相同的问题,直到我完全像这样订购导入和 sys.path.append 之前没有任何效果:
sys.path.append("C:\\Program Files\\IronPython 2.7\\Lib")
sys.path.append("C:\\Program Files\\IronPython 2.7\\Lib\\site-packages")
sys.path.append("C:\\Python27\\Lib")
sys.path.append("C:\\Python27\\Lib\\site-packages")
Ran into the exact same issue, nothing worked until I ordered the imports and sys.path.append exactly like this:
sys.path.append("C:\\Program Files\\IronPython 2.7\\Lib")
sys.path.append("C:\\Program Files\\IronPython 2.7\\Lib\\site-packages")
sys.path.append("C:\\Python27\\Lib")
sys.path.append("C:\\Python27\\Lib\\site-packages")