matplotlib无法导入

时间:2017-09-08 19:12:45

标签: python matplotlib anaconda graphlab

  

AttributeError: 'module' object has no attribute 'cbook'没有回答我的问题。

import matplotlib.pyplot as plt无效。图像中附有错误。

当我运行pip install matplotlib时,它显示已安装。请参阅下面的日志:

Requirement already satisfied (use --upgrade to upgrade): matplotlib in ./anaconda/lib/python2.7/site-packages Requirement already satisfied (use --upgrade to upgrade): numpy>=1.6 in ./anaconda/lib/python2.7/site-packages (from matplotlib) Requirement already satisfied (use --upgrade to upgrade): python-dateutil in ./anaconda/lib/python2.7/site-packages (from matplotlib) Requirement already satisfied (use --upgrade to upgrade): pytz in ./anaconda/lib/python2.7/site-packages (from matplotlib) Requirement already satisfied (use --upgrade to upgrade): cycler in ./anaconda/lib/python2.7/site-packages (from matplotlib) Requirement already satisfied (use --upgrade to upgrade): pyparsing!=2.0.4,>=1.5.6 in ./anaconda/lib/python2.7/site-packages (from matplotlib) Requirement already satisfied (use --upgrade to upgrade): six>=1.5 in ./anaconda/lib/python2.7/site-packages (from python-dateutil->matplotlib)

更新1 根据评论中的建议,尝试在终端中导入相同的内容。以下是输出

>>> import matplotlib.pyplot as plt
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/prabodhprakash/anaconda/lib/python2.7/site-packages/matplotlib/__init__.py", line 122, in <module>
    from matplotlib.cbook import is_string_like, mplDeprecation, dedent, get_label
  File "/Users/prabodhprakash/anaconda/lib/python2.7/site-packages/matplotlib/cbook.py", line 33, in <module>
    import numpy as np
  File "/Users/prabodhprakash/anaconda/lib/python2.7/site-packages/numpy/__init__.py", line 112, in <module>
    from ._globals import ModuleDeprecationWarning, VisibleDeprecationWarning
ImportError: No module named _globals

更新2 按照评论中的建议运行更多命令后,我现在收到此错误:

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-10-385145dcc870> in <module>()
----> 1 import matplotlib.pyplot as plt
      2 get_ipython().magic(u'matplotlib inline')

/Users/prabodhprakash/anaconda/envs/gl-env/lib/python2.7/site-packages/matplotlib/pyplot.py in <module>()
    113 
    114 from matplotlib.backends import pylab_setup
--> 115 _backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
    116 
    117 _IP_REGISTERED = None

/Users/prabodhprakash/anaconda/envs/gl-env/lib/python2.7/site-packages/matplotlib/backends/__init__.pyc in pylab_setup()
     30     # imports. 0 means only perform absolute imports.
     31     backend_mod = __import__(backend_name,
---> 32                              globals(),locals(),[backend_name],0)
     33 
     34     # Things we pull in from all backends

/Users/prabodhprakash/anaconda/envs/gl-env/lib/python2.7/site-packages/matplotlib/backends/backend_macosx.py in <module>()
     17 
     18 import matplotlib
---> 19 from matplotlib.backends import _macosx
     20 
     21 from .backend_agg import RendererAgg, FigureCanvasAgg

RuntimeError: Python is not installed as a framework. The Mac OS X backend will not be able to function correctly if Python is not installed as a framework. See the Python documentation for more information on installing Python as a framework on Mac OS X. Please either reinstall Python as a framework, or try one of the other backends. If you are using (Ana)Conda please install python.app and replace the use of 'python' with 'pythonw'. See 'Working with Matplotlib on OSX' in the Matplotlib FAQ for more information.

1 个答案:

答案 0 :(得分:1)

Unable to "import matplotlib.pyplot as plt" in virtualenv

Installation Issue with matplotlib Python

错误看起来完全不同,但上述两个链接中的解决方案对我来说效果很好。