【问题标题】:No module named fcntl没有名为 fcntl 的模块
【发布时间】:2011-04-04 19:19:36
【问题描述】:

我正在尝试使用 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 模块

【问题讨论】:

    标签: c# module compiler-errors ironpython fcntl


    【解决方案1】:

    fcntl isn't really Windows 原生(平台:Unix)所以你可能不走运,the following StackOverflow thread 可能(或可能没有)有帮助...

    【讨论】:

    • 是的,我也这么想。你能指出在哪里使用 fcntl 吗?因为当我使用 python 26 执行此方法时,它运行良好
    • 当你说 python 26 是指 CPython 吗?
    • 我不确定。我用 IDLE GUI Python 2.6 编译了它。我有点困惑,因为我一直在尝试删除代码的几个部分,以查看 fcntl 信号是如何发出的,但我不走运。
    • 我检查了它,nltk 给出了 fcntl 信号.. 所以如果我在 Windows 操作系统上我不能使用它?
    【解决方案2】:

    当我遇到这个问题时,问题原来是我的搜索路径中只有我的 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 任何地方)

    【讨论】:

      【解决方案3】:

      我认为到目前为止,您最简单的解决方案是切换到 CPython。我认为它的集成度不会低于您现有的解决方案,并且您可以避免缺少模块的所有麻烦。

      【讨论】:

        【解决方案4】:
        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
        

        【讨论】:

          【解决方案5】:

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

          【讨论】:

            猜你喜欢
            • 2017-12-26
            • 2020-10-28
            • 1970-01-01
            • 2019-03-28
            • 2017-12-30
            • 1970-01-01
            • 2018-01-06
            • 2018-11-11
            • 2015-04-10
            相关资源
            最近更新 更多