matplotlib not working in import

4.6k Views Asked by At

AttributeError: 'module' object has no attribute 'cbook' does not answer my question.

import matplotlib.pyplot as plt is not working. Error is attached in the image.

When, I run pip install matplotlib - it shows as already installed. Please see log below:

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)

Update 1 As per a suggestion in comments, tried importing the same in terminal. Following is the output

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

Update 2 After running few more commands, as suggested in comments, I now get this error:

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

There are 0 best solutions below