我正在通過Natural Language Processing with Python書。如何獲取Python shell來查找matplotlib?
我在OSX 10.9上運行Python 2.7.6。 我安裝了numpy 1.8.0。 我安裝了nltk 2.0.4。
我試圖運行此代碼
text4.dispersion_plot(["citizens", "democracy", "freedom", "duties", "America"])
,我得到一個錯誤,告訴我,我需要matplotlib:使用
pip install matplotlib
和
Traceback (most recent call last):
File "<pyshell#14>", line 1, in <module>
monty.dispersion_plot(["quest"])
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/nltk/text.py", line 456, in dispersion_plot
dispersion_plot(self, words)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/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/
我安裝matplotlib這似乎工作,但我得到了同樣的錯誤。顯然Python沒有找到matplotlib。任何人都知道發生了什麼事?
下面是一些可能的線索:
當我運行pip install matplotlib
,我得到
BUILDING MATPLOTLIB
matplotlib: yes [1.3.1]
python: yes [2.7.6 (v2.7.6:3a1db0d2747e, Nov 10 2013,
00:42:54) [GCC 4.2.1 (Apple Inc. build 5666) (dot
3)]]
platform: yes [darwin]
REQUIRED DEPENDENCIES AND EXTENSIONS
numpy: yes [version 1.8.0]
dateutil: yes [dateutil was not found. It is required for date
axis support. pip/easy_install may attempt to
install it after matplotlib.]
tornado: yes [tornado was not found. It is required for the
WebAgg backend. pip/easy_install may attempt to
install it after matplotlib.]
pyparsing: yes [pyparsing was not found. It is required for
mathtext support. pip/easy_install may attempt to
install it after matplotlib.]
pycxx: yes [Couldn't import. Using local copy.]
libagg: yes [pkg-config information for 'libagg' could not
be found. Using local copy.]
freetype: no [The C/C++ header for freetype2 (ft2build.h)
could not be found. You may need to install the
development package.]
png: yes [pkg-config information for 'libpng' could not
be found. Using unknown version.]
也許我需要的FreeType?
我也安裝了Python 3.3.3,並且想知道它們是否會干擾。
這可能是無關的,但即使我已經更新的Tcl/Tk到8.5.15,IDLE似乎並沒有發現它和仍然報告
Python 2.7.6 (v2.7.6:3a1db0d2747e, Nov 10 2013, 00:42:54)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
>>> WARNING: The version of Tcl/Tk (8.5.9) in use may be unstable.
Visit http://www.python.org/download/mac/tcltk/ for current information.