1.在cmd命令提示符窗口中输入:pip install nltk
2.首次输入python代码时,
import nltk
text="Welcome readers. I hope you find it interesting. Please do reply."#需要加空格
from nltk.tokenize import sent_tokenize
print(sent_tokenize(text))`
3.是不是出现了下列所示的错误:
raise LookupError(resource_not_found)
LookupError:
**********************************************************************
Resource punkt not found.
Please use the NLTK Downloader to obtain the resource:
>>> import nltk
>>> nltk.download('punkt')
For more information see: https://www.nltk.org/data.html
Attempted to load tokenizers/punkt/english.pickle
Searched in:
- 'C:\\Users\\Administrator/nltk_data'
- 'C:\\Users\\Administrator\\Desktop\\meatwice\\venv\\nltk_data'
- 'C:\\Users\\Administrator\\Desktop\\meatwice\\venv\\share\\nltk_data'
- 'C:\\Users\\Administrator\\Desktop\\meatwice\\venv\\lib\\nltk_data'
- 'C:\\Users\\Administrator\\AppData\\Roaming\\nltk_data'
- 'C:\\nltk_data'
- 'D:\\nltk_data'
- 'E:\\nltk_data'
- ''
4.解决办法:
在pycharm中输入并运行下列代码
import nltk
nltk.download()
双击punkt即可
5.再次运行下列代码即可
import nltk
text="Welcome readers. I hope you find it interesting. Please do reply."#需要加空格
from nltk.tokenize import sent_tokenize
print(sent_tokenize(text))`