1. 程式人生 > >linux下python3離線加載nltk_data,不用nltk.download()

linux下python3離線加載nltk_data,不用nltk.download()

ren conf com har get 不用 加載 pac 是我

在不能上網的服務器上把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 find nltk_data), see https://stackoverflow.com/a/22987374/610569

linux下python3離線加載nltk_data,不用nltk.download()