I have been trying to make the NLTK (Natural Language Toolkit) work on the Google App Engine. The steps I followed are:
from nltk.tokenize import *
Unfortunately, after launching it I get this error (note that this error is raised deep within NLTK and I'm seeing it for my system installation of python as opposed to the one that is in the sub-folder of the GAE project):
<type 'exceptions.ImportError'>: No module named nltk
Traceback (most recent call last):
File "/base/data/home/apps/xxxx/1.335654715894946084/main.py", line 13, in <module>
from lingua import reducer
File "/base/data/home/apps/xxxx/1.335654715894946084/lingua/reducer.py", line 11, in <module>
from nltk.tokenizer import *
File "/base/data/home/apps/xxxx/1.335654715894946084/lingua/nltk/__init__.py", line 73, in <module>
from internals import config_java
File "/base/data/home/apps/xxxx/1.335654715894946084/lingua/nltk/internals.py", line 19, in <module>
from nltk import __file__
Note: this is how the error looks in the logs when uploaded to GAE. If I run it locally I get the same error (except it seems to originate inside my site-packages instance of NLTK ... so no difference there). And "xxxx" signifies the project name.
So in summary:
EDIT: fixed typo and removed unnecessary step
oakmad has managed to successfully work through deploying SEVERAL NLTK modules to GAE. Hope this helps. But , but be honest, I still don't think it's true even after read the post.
The problem here is that nltk
is attempting to do recursive imports: When nltk/__init__.py
is imported, it imports nltk/internals.py
, which then attempts to import nltk
again. Since nltk
is in the middle of being imported itself, it fails with a (rather unhelpful) error. Whatever they're doing is pretty weird anyway - it's unsurprising something like from nltk import __file__
breaks.
This looks like a problem with nltk itself - does it work when imported directly from a Python console? If so, they must be doing some sort of trickery in the installed version. I'd suggest asking on the nltk groups what they're up to and how to work around it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With