ImportError: No module named matplotlib

Hello. I can’t get past In [1] in Lesson 1. Anaconda appears to be properly installed, and “which python” appears to show the correct path. However, even though matplotlib is installed and updated, it is not findable. Below is the notebook output. Thanks!

%matplotlib inline

 ---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-4-71818a48d801> in <module>()
----> 1 get_ipython().magic(u'matplotlib inline')

/home/harlan/.local/lib/python2.7/site-packages/IPython/core/interactiveshell.pyc in magic(self, arg_s)
   2158         magic_name, _, magic_arg_s = arg_s.partition(' ')
   2159         magic_name = magic_name.lstrip(prefilter.ESC_MAGIC)
-> 2160         return self.run_line_magic(magic_name, magic_arg_s)
   2161 
   2162     #-------------------------------------------------------------------------

/home/harlan/.local/lib/python2.7/site-packages/IPython/core/interactiveshell.pyc in run_line_magic(self, magic_name, line)
   2079                 kwargs['local_ns'] = sys._getframe(stack_depth).f_locals
   2080             with self.builtin_trap:
-> 2081                 result = fn(*args,**kwargs)
   2082             return result
   2083 

<decorator-gen-105> in matplotlib(self, line)

/home/harlan/.local/lib/python2.7/site-packages/IPython/core/magic.pyc in <lambda>(f, *a, **k)
    186     # but it's overkill for just that one bit of state.
    187     def magic_deco(arg):
--> 188         call = lambda f, *a, **k: f(*a, **k)
    189 
    190         if callable(arg):

/home/harlan/.local/lib/python2.7/site-packages/IPython/core/magics/pylab.pyc in matplotlib(self, line)
     98             print("Available matplotlib backends: %s" % backends_list)
     99         else:
--> 100             gui, backend = self.shell.enable_matplotlib(args.gui)
    101             self._show_matplotlib_backend(args.gui, backend)
    102 

/home/harlan/.local/lib/python2.7/site-packages/IPython/core/interactiveshell.pyc in enable_matplotlib(self, gui)
   2936         """
   2937         from IPython.core import pylabtools as pt
-> 2938         gui, backend = pt.find_gui_and_backend(gui, self.pylab_gui_select)
   2939 
   2940         if gui != 'inline':

/home/harlan/.local/lib/python2.7/site-packages/IPython/core/pylabtools.pyc in find_gui_and_backend(gui, gui_select)
    271     """
    272 
--> 273     import matplotlib
    274 
    275     if gui and gui != 'auto':

ImportError: No module named matplotlib

In Ubuntu, check library paths. If not set then do set it.

Thanks, @WaterRocket8236! It turned out to be a server configuration issue.

1 Like

I had this issue, but it was due to using virtualenv (venv) together with jupyter. This worked for me: https://janakiev.com/blog/jupyter-virtual-envs/

I had to manually change kernel.json to point to the correct python interpreter in my virtualenv