2013-06-30 33 views
1

我按照说明从这里巨蟒-3安装matplotlib:How to install matplotlib with Python3.2不能在Python导入matplotlib.pyplot 3

,但我得到一个ImportError,我一直没能解决,进口pyplot时:

>>> import matplotlib 
>>> import matplotlib.pyplot as plt 
Traceback (most recent call last): 
File "<stdin>", line 1, in <module> 
File "/usr/local/lib/python3.2/dist-packages/matplotlib-1.4.x-py3.2-linux-i686.egg/matplotlib/pyplot.py", line 98, in <module> 
_backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup() 
File "/usr/local/lib/python3.2/dist-packages/matplotlib-1.4.x-py3.2-linux-i686.egg/matplotlib/backends/__init__.py", line 25, in pylab_setup 
globals(),locals(),[backend_name]) 
File "/usr/local/lib/python3.2/dist-packages/matplotlib-1.4.x-py3.2-linux-i686.egg/matplotlib/backends/backend_gtk3agg.py", line 1, in <module> 
    import cairo 
ImportError: No module named cairo 

我试过matplotlib.use('Agg')matplotlib.use('GTK')之前导入pyplot,但他们没有区别。

任何帮助将不胜感激,谢谢。

编辑:
这表明我有所有必需的依赖关系。

[email protected]:~/installs/matplotlib$ sudo python3 setup.py --keywords 
============================================================================ 
Edit setup.cfg to change the build options 

BUILDING MATPLOTLIB 
     matplotlib: yes [1.4.x] 
      python: yes [3.2.3 (default, Apr 10 2013, 05:29:11) [GCC 
        4.6.3]] 
      platform: yes [linux2] 

REQUIRED DEPENDENCIES AND EXTENSIONS 
      numpy: yes [version 1.6.1] 
      dateutil: yes [using dateutil version 2.1] 
      tornado: yes [using tornado version 3.1] 
     pyparsing: yes [using pyparsing version 2.0.0] 
      pycxx: yes [Official versions of PyCXX are not compatible 
        with Python 3.x. Using local copy] 
      libagg: yes [pkg-config information for 'libagg' could not 
        be found. Using local copy.] 
      freetype: yes [version 14.0.8] 
       png: yes [version 1.2.46] 

OPTIONAL SUBPACKAGES 
     sample_data: yes [installing] 
      toolkits: yes [installing] 
      tests: yes [using nose version 1.3.0] 

OPTIONAL BACKEND EXTENSIONS 
      macosx: no [Mac OS-X only] 
      qt4agg: no [PyQt4 not found] 
      gtk3agg: yes [gtk3agg backend does not work on Python 3] 
     gtk3cairo: no [Requires cairo to be installed.] 
      gtkagg: no [Requires pygtk] 
      tkagg: yes [version version not identified] 
      wxagg: no [requires wxPython] 
       gtk: no [Requires pygtk] 
       agg: yes [installing] 
      cairo: no [cairo not found] 
     windowing: no [Microsoft Windows only] 

OPTIONAL LATEX DEPENDENCIES 
      dvipng: yes [version 1.14] 
     ghostscript: yes [version 9.05] 
      latex: yes [version 3.1415926] 
      pdftops: yes [version 0.18.4] 
+1

您是如何安装matplotlib的?使用包管理器,比如apt-get,或者从setup.py? –

+0

你可能还没有安装[pycairo](https://pypi.python.org/pypi/pycairo) – mata

+0

“...他们没有区别”,因为你仍然得到*一个* ImportError或*这个特殊的*'ImportError'? –

回答

1

问题原因在Mac OS图像渲染回到matplotlib结束(什么 - 是-A-后端,可使用可可的API默认情况下)。有Qt4Agg和GTKAgg,作为后端不是默认设置。设置不同于其他窗口或linux操作系统的macosx的后端。

我按照以下方式解决了这个问题,我假设你已经安装了pip matplotlib,在你的根目录中有一个名为〜/的目录。 matplotlib。创建一个名为matplotlibrc的文件,其中包含以下代码

~/.matplotlib/Matplotlibrc 
backend: TkAgg