【问题标题】:How to get Python shell to find matplotlib?如何让 Python shell 找到 matplotlib?
【发布时间】:2014-01-05 18:28:48
【问题描述】:

我正在阅读Natural Language Processing with Python 的书。

我在 OSX 10.9 上运行 Python 2.7.6。 我安装了 numpy 1.8.0。 我已经安装了 nltk 2.0.4。

我正在尝试运行此代码

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

我收到一条错误消息,告诉我我需要 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 使用

pip install 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.

【问题讨论】:

    标签: python matplotlib


    【解决方案1】:

    看起来 pip 正在更新你的 2.7 版本的 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)]]
    

    查看here,了解有关为 2.x 和 3.x 获取多个 pip 实例的更多信息。

    【讨论】:

      【解决方案2】:

      如果可以,我会尝试以超级用户身份运行 pip install matplotlib,这曾经解决了我遇到的类似问题。

      【讨论】:

        【解决方案3】:

        一种解决方法是执行sudo apt-get install pkg-config,我找到了in this github issue

        【讨论】:

          猜你喜欢
          • 2017-05-08
          • 2018-03-26
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多