没有名为 fcntl 的模块

发布于 2024-10-29 07:38:35 字数 1288 浏览 1 评论 0原文

我正在尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

此刻的回忆 2024-11-05 07:38:35

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...

雪落纷纷 2024-11-05 07:38:35

当我遇到这个问题时,问题是我的搜索路径中只有我的 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 源代码在任何地方都不包含字符串 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

 engine.SetSearchPaths(new string[] {"C:\\Program Files\\IronPython 2.7\\Lib"
                                    ,"C:\\Python27\\Lib"
                                    ,"C:\\Python27\\Lib\\site-packages"
                                    });

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)

梦巷 2024-11-05 07:38:35

我认为到目前为止最简单的解决方案是切换到 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.

双马尾 2024-11-05 07:38:35
import sys
sys.path.append("X:\Python27x64")
sys.path.append("X:\Python27x64\DLLs")
sys.path.append("X:\Python27x64\Lib")
sys.path.append("X:\Python27x64\Lib\site-packages")
sys.platform = "win32"
import nltk
import sys
sys.path.append("X:\Python27x64")
sys.path.append("X:\Python27x64\DLLs")
sys.path.append("X:\Python27x64\Lib")
sys.path.append("X:\Python27x64\Lib\site-packages")
sys.platform = "win32"
import nltk
我们只是彼此的过ke 2024-11-05 07:38:35

遇到了完全相同的问题,直到我完全像这样订购导入和 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")

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文