1

I am a beginner at programming and I am working on an online course which uses ipython and jupyter notebook. I am working with Mac OS 10.13.3.

I have tried importing matplotlib as follows,

import matplotlib.pyplot as plt
%matplotlib inline

However, the following error is being generated.

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

/Users/Varshil/anaconda/envs/gl-env/lib/python2.7/site-packages/matplotlib/pyplot.py in <module>()
     27 from cycler import cycler
     28 import matplotlib
---> 29 import matplotlib.colorbar
     30 from matplotlib import style
     31 from matplotlib import _pylab_helpers, interactive

/Users/Varshil/anaconda/envs/gl-env/lib/python2.7/site-packages/matplotlib/colorbar.py in <module>()
     30 
     31 import matplotlib as mpl
---> 32 import matplotlib.artist as martist
     33 import matplotlib.cbook as cbook
     34 import matplotlib.collections as collections

/Users/Varshil/anaconda/envs/gl-env/lib/python2.7/site-packages/matplotlib/artist.py in <module>()
      9 import numpy as np
     10 import matplotlib
---> 11 import matplotlib.cbook as cbook
     12 from matplotlib.cbook import mplDeprecation
     13 from matplotlib import docstring, rcParams

AttributeError: 'module' object has no attribute 'cbook'

It would be of great help if someone could help me solve this issue. I have tried looking up online but have found no successful leads.

4
  • 1
    Something went wrong when installing matplotlib. Try to uninstall and reinstall again. Commented Feb 12, 2018 at 11:49
  • Also see this question. Commented Feb 12, 2018 at 12:06
  • @ImportanceOfBeingErnest Initially, I installed the whole package using graph lab create launcher. So I uninstalled the graph lab launcher and installed it again. I checked after uninstallation whether matplotlib exists and it did not. However the issue still remains. Commented Feb 12, 2018 at 13:39
  • I have tried finding which matplotlib has been imported by typing... import imp imp.find_module("matplotlib") This is the result. (None, '/Users/Varshil/anaconda/envs/gl-env/lib/python2.7/site-packages/matplotlib', ('', '', 5)) Can someone explain what this means? Commented Feb 13, 2018 at 6:05

1 Answer 1

1

This is because you are using old version of matplotlib.

Those who are using GraphLab Create, first activate virtual environment:

source gl-env/bin/activate

Now upgrade matplotlib:

pip install -U matplotlib

Output:

Found existing installation: matplotlib 1.5.1 Uninstalling matplotlib-1.5.1: Successfully uninstalled matplotlib-1.5.1 Successfully installed matplotlib-2.1.2

Restart iPython/Jupyter.

If you are on Mac, you might get the following error:

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.

Create a file ~/.matplotlib/matplotlibrc there and add the following code: backend: TkAgg

Again restart iPython/Jupyter.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.