0

I am trying to use a python module (nltk) in web2py.

I am able to use the module from the python command line without issues. In Web2py I get the error below.

Thanks!

Simple example Code:

import nltk
from nltk.corpus import wordnet as wn

def get_thes():
    wn.synset('car.n.01').lemma_names
    return dict()

Error

web2py™ Version 2.5.1-stable+timestamp.2013.06.06.15.39.19
Python  Python 2.7.3: /usr/bin/python (prefix: /usr)

Traceback (most recent call last):
  File "/home/www-data/web2py/gluon/restricted.py", line 212, in restricted
    exec ccode in environment
  File "/home/www-data/web2py/applications/Wordgf/controllers/thes.py", line 1, in <module>
    import nltk
  File "/home/www-data/web2py/gluon/custom_import.py", line 95, in custom_importer
    raise e2  # there is an error in the module
AttributeError: 'module' object has no attribute 'error'
thefourtheye
  • 233,700
  • 52
  • 457
  • 497
user2495294
  • 27
  • 1
  • 6
  • I tried this and i didnt get this error http://pastebin.com/pQPe3k7E – thefourtheye Jun 18 '13 at 01:12
  • @thefourtheye: I looked at what you did, it looks like you have not yet downloaded the wordnet add-on. Im guessing thats why you get the error. Unless i'm missing something? – user2495294 Jun 18 '13 at 13:37
  • But I am able to get past the `import nltk` I believe. – thefourtheye Jun 18 '13 at 13:41
  • @thefourtheye. Thanks. I noticed you were using the web2py web server. I am using apache so I tried to do a restart and I now get the same error you do. I went into python and did the nltk download - it tells me that package 'Wordnet' is already up to date. Is there anything specific I need to do in web2py for this? – user2495294 Jun 18 '13 at 14:22
  • 1
    You might want to look at http://stackoverflow.com/questions/13965823/resource-corpora-wordnet-not-found-on-heroku – thefourtheye Jun 18 '13 at 14:32

1 Answers1

0

Only the source version of web2py is able to import modules.

Make sure you are not using a compiled version.

hirolau
  • 13,451
  • 8
  • 35
  • 47