在Jupyter笔记本电脑上找不到Matplotlib

时间:2020-07-09 17:34:25

标签: python python-3.x matplotlib jupyter-notebook ipython

我是命令行编程的新手,所以请多多包涵。我一直在尝试使用以下命令在Jupyter笔记本中内联运行matplotlib:

%matplotlib inline

我收到以下错误

ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-1-88ca88d21acc> in <module>
      2 #We will use this to think about regression
      3 import numpy as np
----> 4 get_ipython().run_line_magic('matplotlib', 'inline')
      5 
      6 from sklearn import datasets, linear_model

~/.pyenv/versions/jupyter3/lib/python3.8/site-packages/IPython/core/interactiveshell.py in run_line_magic(self, magic_name, line, _stack_depth)
   2324                 kwargs['local_ns'] = sys._getframe(stack_depth).f_locals
   2325             with self.builtin_trap:
-> 2326                 result = fn(*args, **kwargs)
   2327             return result
   2328 

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

~/.pyenv/versions/jupyter3/lib/python3.8/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):

~/.pyenv/versions/jupyter3/lib/python3.8/site-packages/IPython/core/magics/pylab.py in matplotlib(self, line)
     97             print("Available matplotlib backends: %s" % backends_list)
     98         else:
---> 99             gui, backend = self.shell.enable_matplotlib(args.gui.lower() if isinstance(args.gui, str) else args.gui)
    100             self._show_matplotlib_backend(args.gui, backend)
    101 

~/.pyenv/versions/jupyter3/lib/python3.8/site-packages/IPython/core/interactiveshell.py in enable_matplotlib(self, gui)
   3417         """
   3418         from IPython.core import pylabtools as pt
-> 3419         gui, backend = pt.find_gui_and_backend(gui, self.pylab_gui_select)
   3420 
   3421         if gui != 'inline':

~/.pyenv/versions/jupyter3/lib/python3.8/site-packages/IPython/core/pylabtools.py in find_gui_and_backend(gui, gui_select)
    278     """
    279 
--> 280     import matplotlib
    281 
    282     if gui and gui != 'auto':

ModuleNotFoundError: No module named 'matplotlib'

在命令行上同时运行python和Ipython之后,我确信它们都通过相同的python 3.8.3安装运行。如果是这种情况,我不确定为什么matplotlib库对pylabtools.py脚本不可用。

作为参考,我按照https://medium.com/@henriquebastos/the-definitive-guide-to-setup-my-python-workspace-628d68552e14上的说明安装了所有程序。

0 个答案:

没有答案