1.Mac安装Python3.6
安装好命令行自带python3.6 pip3.6
Mac系统自带的python环境默认启动路径在:/usr/bin
用户安装的python环境默认启动路径在:/usr/local/bin
2.安装NLTK
1.Install NLTK: run pip3.6 install -U nltk
2.Install Numpy (optional): run pip3.6 install -U numpy
3.Test installation: run python3.6
then type import nltk
4.来安装所需的数据nltk.download()
4.1遇到nltk downloader ssl error错误解决方案:(https://stackoverflow.com/questions/41348621/ssl-error-downloading-nltk-data)
Install certificates
1.Change directory to the python folder: cd /Applications/Python 3.6/
2.Run the command: ./Install Certificates.command
3.一些错误
generate
实例:
>>> text3.generate()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: generate() missing 1 required positional argument: 'words'
>>>
产生一些与text3风格类似的随机文本。但在本机上却出错,原因是我使用的是nltk3.3和Python3.6,该版本下generate函数被注释了,所以无法使用。
而《python自然语言处理时》书中用的是NLTK2.0版本。
代码:
>>> fdist1 = FreqDist(text1)
>>> vocabulary1 = fdist1.keys()
>>> vocabulary1[:50]
错误:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'dict_keys' object is not subscriptable
https://stackoverflow.com/questions/26394748/nltk-python-error-typeerror-dict-keys-object-is-not-subscriptable
在python3下使用:
vocabulary1 = list(fdist1.keys())
或者:
fdist1.most_common(200)