3

I am trying to use rPython to import some of the nltk functionality into my R program. My test function is,

test.py

import random, numpy,nltk
import sys

print (sys.version)

number = random.randint(1, 1000)

print(number)
string = nltk.word_tokenize('home sweet home')

print(string)

Running the code from console it runs fine,

python test.py

2.7.10 (default, Sep 23 2015, 04:34:21) 
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.72)]
331
['home', 'sweet', 'home']

Running from R however, I am encountering this problem,

library(rPython)
python.load("test.py")
Error in python.exec(code, get.exception) : No module named nltk

same with RStudio. If I remove "nltk" then things work fine,

python.load("test.py")

2.7.10 (default, Aug 22 2015, 20:33:39) 
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.1)]
386

Seems both of them using the same version of python 2.7 I see this user having a similar issue but only with RStudio. RStudio doesn't load all Python modules via rPython call

Community
  • 1
  • 1
DonDyck
  • 1,451
  • 5
  • 20
  • 35
  • What's the `sys.path` in your various pythons? That's where python looks for modules. `import sys` then look at `sys.path`. Should also let you tell if it really is the same python interpreter (dont be fooled just because the version is the same...). Ooh actually the python and `clang` versions are different... Methinks two different pythons, one without `nltk` installed... – Spacedman Dec 21 '15 at 18:05

0 Answers0