Instead of adding nltk.data.path.append('your/path/to/nltk_data') to each script, NLTK accepts the NLTK_DATA environment variable. ( link to code )
Open ~/.bashrc (or ~/.profile ) with a text editor (e.g. nano , vim , gedit ) and add the following line:
export NLTK_DATA="your/path/to/nltk_data"
Run source to load the environment variable
source ~/.bashrc
Test
Open python and execute the following lines
import nltk nltk.data.path
You can see your nltk data path already there.
Link: @alvations answer to nltk / nltk # 1997
fnjn Apr 02 '18 at 9:23 2018-04-02 09:23
source share