pythonnltkweb2pyweb2py-modules

Importing NLTK to web2py


I am trying to use NLTK in web2py. I am able to run NLTK in Python command line and in python scripts but I get an import error:

<type 'exceptions.ImportError'> Cannot import module 'applications.DeepThought.modules.nltk'

I have stripped the code down to nothing and this is the offensive code:

# -*- coding: utf-8 -*-
import time
import nltk

def task_waiter(a):
    time.sleep(a)
    return dict()

def task_add(a,b):
    return a+b

def b(a):

    return dict()

def d(a):
    return dict()

from gluon.scheduler import Scheduler
scheduler = Scheduler(DTtaskDb)

I am not even having problems with getting the NLTK corpus, but I imagine that is an issue when I did my searches nobody else was having problems simply importing NLTK.

This is my version information: web2py™ Version 2.14.3-stable+timestamp.2016.03.26.23.02.02 Python Python 2.7.3: /Volumes/Macintosh HD 2/Web2Py/web2py.app/Contents/MacOS/python (prefix: /Volumes/Macintosh HD 2/Web2Py/web2py.app/Contents/Resources)


Solution

  • It appears you are running the OSX binary version of web2py, which includes its own Python interpreter and therefore ignores your system's Python installation (and any of its installed libraries, such as NLTK). If you have your own Python installation, you should instead download and run the source version of web2py.