1

I've got a copy of Lion with all the dev tools installed. Both Python (2.7) and Ruby (1.8) are running just fine. I've installed the Natural Language Tool Kit for Python and tried it out in the Python interpreter and it works

import nltk
>>true

So that works. I've also installed the RubyPython gem, and it seems to work too, but it can't find the nltk module. It's possible I'm doing something wrong. In irb:

require "RubyGems"
require "rubypython" #both true
RubyPython.start # true
n = RubyPython.import "nltk" # RubyPython::PythonError: ImportError: No module named nltk
c = RubyPython.import "cPickle" # works!
RubyPython.stop

I can't figure this one out. The PythonError seems to indicate to me (because it's just a call to the direct C APIs) that the nltk module can't be found by any form of python. But the interpreter finds it just fine. RubyPython, however, cannot.

I've also tried forcing RubyPython to use python2.7 but no change.

What am I missing?

jbrennan
  • 11,943
  • 14
  • 73
  • 115
  • 1
    Try printing the path. What do you get? I'm not sure about RubyPython, but in Python it would be `import sys; print sys.path`. Check to see where nltk is installed, and if that path appears in sys.path in RubyPython. If not, add it to sys.path, or to your $PATH or $PYTHONPATH. – Vlad the Impala Apr 02 '12 at 07:13
  • Yeah, I ended up figuring that out yesterday but wasn't able to post an answer. For whatever reason, RubyPython was using a different path. I imported the path, added the location of NLTK to it, and presto, it worked. – jbrennan Apr 02 '12 at 18:22

1 Answers1

1

It's simple! For some reason, RubyPython was looking in the wrong place for my Python modules. This was verified by importing sys in both the RubyPython script and in Python, and comparing sys.path. I ended up fixing it by taking the path list of sys in the Ruby script and adding what was missing from the pure Python's path. Then I could load NLTK.

jbrennan
  • 11,943
  • 14
  • 73
  • 115