簡體   English   中英

Jupyter Notebook`pylab inline`給出`matplotlib`錯誤

[英]Jupyter notebook `pylab inline` gives `matplotlib` error

以前,我在運行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,但沒有解決方案。

有解決方案嗎?

不要使用%pylab ,它已被棄用。 使用以下任一方法:

%matplotlib inline

%matplotlib notebook

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM