3

I'm working through the Natural Language Processing with Python book.

I'm running Python 2.7.6 on OSX 10.9. I have numpy 1.8.0 installed. I have nltk 2.0.4 installed.

I'm trying to run this code

text4.dispersion_plot(["citizens", "democracy", "freedom", "duties", "America"])

and I get an error telling me that I need 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/

I installed matplotlib using

pip install matplotlib 

and that seems to have worked, but I get the same error. Apparently Python is not finding matplotlib. Anyone know what's going on?

Here are some possible clues:

When I run pip install matplotlib, I get

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.]

Maybe I need freetype?

I also have Python 3.3.3 installed, and am wondering if they're interfering.

This is probably unrelated, but even though I've updated Tcl/Tk to 8.5.15, IDLE doesn't seem to have found it and still reports

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.
mob
  • 31
  • 3

3 Answers3

0

It looks like pip is updating your 2.7 version of python.

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)]]

Look here for more information on getting multiple instances of pip for 2.x and 3.x.

Community
  • 1
  • 1
nfazzio
  • 498
  • 1
  • 3
  • 12
0

If you are able, I would give it a try to run pip install matplotlib as super user, that once fixed a similar problem I had.

eguaio
  • 3,754
  • 1
  • 24
  • 38
0

A workaround is to do sudo apt-get install pkg-config which I found in this github issue.

notconfusing
  • 2,556
  • 3
  • 22
  • 26