How to config nltk data directory from code?
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Evil ctypes hack in python
- Correctly parse PDF paragraphs with Python
From the code, http://www.nltk.org/_modules/nltk/data.html:
Then within the code:
To modify the path, simply append to the list of possible paths:
Or in windows:
I use append, example
Instead of adding
nltk.data.path.append('your/path/to/nltk_data')
to every script, NLTK accepts NLTK_DATA environment variable. (code link)Open
~/.bashrc
(or~/.profile
) with text editor (e.g.nano
,vim
,gedit
), and add following line:Execute
source
to load environmental variableTest
Open python and execute following lines
Your can see your nltk data path already in there.
Reference: @alvations's answer on nltk/nltk #1997
For those using uwsgi:
I was having trouble because I wanted a uwsgi app (running as a different user than myself) to have access to nltk data that I had previously downloaded. What worked for me was adding the following line to
myapp_uwsgi.ini
:This sets the environment variable
NLTK_DATA
, as suggested by @schemacs.You may need to restart your uwsgi process after making this change.
Just change items of
nltk.data.path
, it's a simple list.