9

I'm using Visual Studio 2010. I have an IronPython console project and a C# console project. This IronPython script works fine when I run it by itself:

import nltk

def Simple():
    baconIpsumFile = open('baconipsum.txt', 'r')
    baconIpsumCorpus = baconIpsumFile.read()

    tokens = nltk.word_tokenize(baconIpsumCorpus)
    text = nltk.Text(tokens)
    print text

Here is the C# console program, which does not work fine:

using IronPython.Hosting;

namespace IronNLTK.CSharp.Console
{
    class Program
    {
        static void Main(string[] args)
        {
            var ipy = Python.CreateRuntime();
            dynamic test = ipy.UseFile("C:\\Path\\To\\Program.py");
            test.Simple();
        }
    }
}

I get an ImportException: No module named nltk. What am I missing?

2
  • 1
    Can you interact with the ipy runtime and adjust the path there? Commented Sep 19, 2011 at 14:19
  • I've also tried that. I.e. the accepted answer in stackoverflow.com/questions/1371994/… Commented Sep 19, 2011 at 14:41

2 Answers 2

3

sounds like you need to update sys.path to point to wherever NLTK lives.

check this out: Importing external module in IronPython

Sign up to request clarification or add additional context in comments.

4 Comments

if you mean something like sys.path.append(r"c:\Program Files (x86)\IronPython\Lib") that doesn't work either
Of course that does not work. Backslash is the string escape character. If you want to put a path in a Python string, then you need to do C:/Progr... or C:\\Progr...
In addition, it is not unusual for portable software to have a problem with paths that contain spaces in the name. Have you tried installing another instance of IronPython in C:\IronPython so that you don't have any directories with space in the names?
Yes, sorry, I did use escaped backslashes, I'll look into the spaces in the path name though...
2

Awesome news, Visual Studio 2017 is embedded with Anaconda’s Python distribution which has NTLK and other machine learning packages.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.