最近我正在学习在 Windows 7 上使用 nltk。我为 Python 2.7 安装了 Python2.7 和 NumPy1.6.2 以及 matplotlib 1.3.0。但是当我尝试运行以下代码时,它就无法工作(第一行工作正常):
from nltk.book import *
text4.dispersion_plot(["citizens", "democracy", "freedom", "duties", "America"])
代码来自《Natural Languages Processing with Python 》一书。错误信息如下:
Traceback (most recent call last):
File "<pyshell#6>", line 1, in <module>
text4.dispersion_plot(["citizens", "democracy", "freedom", "duties", "America"])
File "D:\Program Files\Python27\lib\site-packages\nltk\text.py", line 456, in dispersion_plot
dispersion_plot(self, words)
File "D:\Program Files\Python27\lib\site-packages\nltk\draw\dispersion.py", line 27, in dispersion_plot
raise ValueError('The plot function requires the matplotlib package (aka pylab).'
ValueError: The plot function requires the matplotlib package (aka pylab).See http://matplotlib.sourceforge.net/
我怎样才能让它正常工作?非常感谢。