2

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

michelle
  • 2,759
  • 4
  • 31
  • 46

5 Answers5

3

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

Community
  • 1
  • 1
ChristopheD
  • 112,638
  • 29
  • 165
  • 179
  • yeah i thought as much. could you indicate where fcntl would be used? since when i executed this method using python 26, it worked well – michelle Apr 04 '11 at 19:31
  • when you say python 26 do you mean CPython? – David Heffernan Apr 04 '11 at 19:40
  • I am not sure. I compiled it with IDLE GUI Python 2.6. I am bit confused, since I have been trying to remove several parts of the code, to see how the fcntl signal is being issued but I am out of luck. – michelle Apr 04 '11 at 19:51
  • i checked it out and nltk gives the fcntl signal.. so i cannot use it if im on a windows OS? – michelle Apr 04 '11 at 20:27
1

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)

kowey
  • 1,211
  • 7
  • 15
0
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
InoriXu
  • 56
  • 1
  • 3
0

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.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
0

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")

Radu
  • 13
  • 5