No module named fcntl

亡梦爱人 提交于 2019-12-12 17:18:06

问题


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


回答1:


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.




回答2:


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




回答3:


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)




回答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


来源:https://stackoverflow.com/questions/5543229/no-module-named-fcntl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!