python - different nltk results in django and at command line -


i have django 1.8 view looks this:

def sourcedoc_parse(request, sourcedoc_id):     sourcedoc = sourcedoc.objects.get(pk=sourcedoc_id)     nltk.data.path.append('/root/nltk_data')     new_words = []     english_vocab = set(w.lower() w in nltk.corpus.gutenberg.words())    #<---the line error occurs     results = {}      template = 'sourcedoc_parse.html'     params = {'sourcedoc': sourcedoc,'results': results, 'new_words': new_words, 'base_url': base_url}      return render_to_response(template, params, context_instance=requestcontext(request)) 

it gives me following error:

django version: 1.8 python version: 2.7.6 ... traceback: file "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response 132.                     response = wrapped_callback(request, *callback_args, **callback_kwargs) file "/home/rosshartshorn/htdocs/worldmaker/sourcedocs/views.py" in sourcedoc_parse 107.     english_vocab = set(w.lower() w in nltk.corpus.gutenberg.words()) file "/usr/local/lib/python2.7/dist-packages/nltk/corpus/util.py" in __getattr__ 68.         self.__load() 

file "/usr/local/lib/python2.7/dist-packages/nltk/corpus/util.py" in __load 56. except lookuperror: raise e

exception type: lookuperror @ /sourcedoc/parse/13/ exception value:  ********************************************************************** resource 'corpora/gutenberg' not found.  please use nltk downloader obtain resource:  >>> nltk.download() searched in: - '/var/www/nltk_data' - '/usr/share/nltk_data' - '/usr/local/share/nltk_data' - '/usr/lib/nltk_data' - '/usr/local/lib/nltk_data' - '/root/nltk_data' ********************************************************************** 

what odd works fine when in same directory in python shell, works fine:

python 2.7.6 (default, mar 22 2014, 22:59:38)  [gcc 4.8.2] on linux2 type "help", "copyright", "credits" or "license" more information. >>> import nltk >>> english_vocab = set(w.lower() w in nltk.corpus.gutenberg.words()) >>> 'jabberwocky' in english_vocab false >>> 'monster' in english_vocab true >>> nltk.data.path ['/root/nltk_data', '/usr/share/nltk_data', '/usr/local/share/nltk_data', '/usr/lib/nltk_data', '/usr/local/lib/nltk_data'] 

does have idea source of difference between running inside view in django, , doing same thing @ python command line? i've done same thing using 'python manage.py shell', , works way.

any debugging advice on finding difference welcome.

the problem here user running django don't have permission read @ /root.

it not happens when running django shell because running shell root, server running www user (see, first directory nltk search /var/www/nltk_data, home dir www user).


Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -