Jupyter Notebook`pylab inline`给出`matplotlib`错误

时间:2018-10-15 20:19:36

标签: python jupyter-notebook

以前,我是在运行Python 3.7的Mac上从事Jupyter笔记本项目的工作。

今天,当我想加载笔记本电脑的%pylab inline机器时,收到了错误消息:

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

我尝试过在线寻找解决方案。

我删除了Python 3.6,从头开始重新安装了brew,使用终端从头开始重新安装了jupyter,但没有解决方案。

有解决方案吗?

1 个答案:

答案 0 :(得分:0)

请勿使用%pylab,已弃用。使用以下任一方法:

%matplotlib inline

%matplotlib notebook