[mod_python] Using NLTK with mod_python

Dan Yamins dyamins at gmail.com
Sun Jan 24 00:47:41 EST 2010


>
>
> File "C:\Python25\lib\os.py", line 433, in __getitem__
> return self.data[key.upper()]
>
> KeyError: 'APPDATA'
>
>
In general, The above error message means that a python dictionary (see
http://docs.python.org/tutorial/datastructures.html, section 5.5)  is being
asked for a key that it doesn't have.  This portion of the message:

.....
>
>   File "C:\Python25\Lib\site-packages\nltk\data.py", line 80, in <module>
>     os.path.join(os.environ['APPDATA'], 'nltk_data')]
>
>
tells us that the dictionary "os.environ" doesn't have the 'APPDATA' key.
The os.environ is the dictionary of environment variables in the shell that
launched process.  (See http://docs.python.org/library/os.html)  So, the
ultimate point is that an environment variable that needs to be defined for
nltk to work is not defined.

I can't tell you what "APPDATA' is supposed to refer to .. but probably it's
something that's suppose to be set by the user of NLTK to locate a file
resource needed for operation of the package.

Assuming you know what the value APPDATA should be ... you can use
os.environ to set the proper value before importing nltk, or you can set it
in the shell that launches the process ... (I'm not that familar with
Windows, so I can't give you precise details on how to set environment
variables there .. but you can google it easily.)

If you don't know what value APPDATA is supposed to be set at in the first
place, you should probably either look in NLTK documentation  or write to an
NLTK user group.


Hth,
Dan



> My code is:
> from mod_python import apache
> import sys
> import nltk
>
> def handler(req):
> 	req.content_type = 'text/plain'
> 	s= sys.version
> 	req.write(s)
> 	
> 	return apache.OK
>
>
> I'm sure I'm doing something dumb, but with one day's experience of Python
> - told you I was a noob - I haven't the foggiest. I've googled obvious
> terms, but with no luck.
>
> Any ideas?
> Thanks,
> Chris
>
> _______________________________________________
> Mod_python mailing list
> Mod_python at modpython.org
> http://mailman.modpython.org/mailman/listinfo/mod_python
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mm_cfg_has_not_been_edited_to_set_host_domains/pipermail/mod_python/attachments/20100124/ab2eee78/attachment.html


More information about the Mod_python mailing list