0

Previously, I was working on a Jupyter notebook project on a mac running Python 3.7.

Today, when I wanted to load the notebook's %pylab inline machinery, I received the error:

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-1-a6e0d37a4680> in <module>
----> 1 get_ipython().run_line_magic('pylab', 'inline')

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/IPython/core/interactiveshell.py in run_line_magic(self, magic_name, line, _stack_depth)
   2283                 kwargs['local_ns'] = sys._getframe(stack_depth).f_locals
   2284             with self.builtin_trap:
-> 2285                 result = fn(*args,**kwargs)
   2286             return result
   2287 

<decorator-gen-108> in pylab(self, line)

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/IPython/core/magic.py in <lambda>(f, *a, **k)
    185     # but it's overkill for just that one bit of state.
    186     def magic_deco(arg):
--> 187         call = lambda f, *a, **k: f(*a, **k)
    188 
    189         if callable(arg):

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-        packages/IPython/core/magics/pylab.py in pylab(self, line)
    153             import_all = not args.no_import_all
    154 
--> 155         gui, backend, clobbered = self.shell.enable_pylab(args.gui, import_all=import_all)
    156         self._show_matplotlib_backend(args.gui, backend)
    157         print ("Populating the interactive namespace from numpy and matplotlib")

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/IPython/core/interactiveshell.py in enable_pylab(self, gui, import_all, welcome_message)
   3390         from IPython.core.pylabtools import import_pylab
   3391 
-> 3392         gui, backend = self.enable_matplotlib(gui)
   3393 
   3394         # We want to prevent the loading of pylab to pollute the user's

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/IPython/core/interactiveshell.py in enable_matplotlib(self, gui)
   3339         """
   3340         from IPython.core import pylabtools as pt
-> 3341         gui, backend = pt.find_gui_and_backend(gui, self.pylab_gui_select)
   3342 
   3343         if gui != 'inline':

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/IPython/core/pylabtools.py in find_gui_and_backend(gui, gui_select)
    274     """
    275 
--> 276     import matplotlib
    277 
    278     if gui and gui != 'auto':

ModuleNotFoundError: No module named 'matplotlib'

I've tried looking for solutions online.

I have removed Python 3.6, reinstalled brew from scratch, reinstalled jupyter from scratch using the terminal but to no solution.

Is there a solution?

1 Answer 1

1

Don't use %pylab, it is deprecated. Use either:

%matplotlib inline

or %matplotlib notebook

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.