linux下python3离线加载nltk_data,不用nltk.download()
在不能上网的服务器上把nltk_data关联到python3,已经安装anaconda3所以不需要安装nltk,环境是linux
首先没有nltk_data在使用nltk会报错
LookupError: ********************************************************************** Resource 'tokenizers/punkt/PY3/english.pickle' not found. Please use the NLTK Downloader to obtain the resource: >>> nltk.download() Searched in: - '/home/hadoopcj/nltk_data' - '/usr/share/nltk_data' - '/usr/local/share/nltk_data' - '/usr/lib/nltk_data' - '/usr/local/lib/nltk_data' - '/home/hadoopcj/nltk_data' - ''
1.下载nltk_data
https://github.com/nltk/nltk_data
里面的Packages就是我们要的资源。
2.里面有部分是压缩包,需要解压。punkt就是,不解压即使路径对了还是会报上面的错误
3.将Packages文件夹改名为nltk_data,拷贝到服务器
4.进入python console(如输入/home/hadoopcj/anaconda3/bin/python3.6)在nltk添加你data的路径
>>>from nltk import data >>>data.path.append(r"/home/hadoopcj/nltk_data(你的路径)")
5.查看nltk_data的搜索路径,如果有你添加的就成功了
>>> nltk.data.path
>>> nltk.data.path ['/home/hadoopcj/nltk_data', '/usr/share/nltk_data', '/usr/local/share/nltk_data', '/usr/lib/nltk_data', '/usr/local/lib/nltk_data']
Related
-
To find
nltk_data
directory (auto-magically), see https://stackoverflow.com/a/36383314/610569 -
To download
nltk_data
to a different path, see https://stackoverflow.com/a/48634212/610569 -
To config
nltk_data
path (i.e. set a different path for NLTK to findnltk_data
), see https://stackoverflow.com/a/22987374/610569