Jupyter Notebook甚至无法正常工作

时间:2020-06-14 01:02:21

标签: python jupyter-notebook

由于某种原因,我什至无法运行此基本行。它应该只接受它,但它甚至不会这样做。每次我打开Jupyter Notebook时,都会发生类似的情况。当然,实际上没有任何方法可以永久修复它。我没有太多可以尝试的方法,但是与Jupyter混为一谈也使我的其他IDE搞砸了。

from __future__ import print_function, division

%matplotlib inline

import numpy as np

import nsfg
import first


---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-1-58d7125e1e68> in <module>
      1 from __future__ import print_function, division
      2 
----> 3 get_ipython().run_line_magic('matplotlib', 'inline')
      4 
      5 import numpy as np

~/opt/anaconda3/lib/python3.7/site-packages/IPython/core/interactiveshell.py in run_line_magic(self, magic_name, line, _stack_depth)
   2315                 kwargs['local_ns'] = sys._getframe(stack_depth).f_locals
   2316             with self.builtin_trap:
-> 2317                 result = fn(*args, **kwargs)
   2318             return result
   2319 

</Users/hedyeherfani/opt/anaconda3/lib/python3.7/site-packages/decorator.py:decorator-gen-108> in matplotlib(self, line)

~/opt/anaconda3/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):

~/opt/anaconda3/lib/python3.7/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 

~/opt/anaconda3/lib/python3.7/site-packages/IPython/core/interactiveshell.py in enable_matplotlib(self, gui)
   3417                 gui, backend = pt.find_gui_and_backend(self.pylab_gui_select)
   3418 
-> 3419         pt.activate_matplotlib(backend)
   3420         pt.configure_inline_support(self, backend)
   3421 

~/opt/anaconda3/lib/python3.7/site-packages/IPython/core/pylabtools.py in activate_matplotlib(backend)
    318     # when this function runs.
    319     # So avoid needing matplotlib attribute-lookup to access pyplot.
--> 320     from matplotlib import pyplot as plt
    321 
    322     plt.switch_backend(backend)

~/opt/anaconda3/lib/python3.7/site-packages/matplotlib/pyplot.py in <module>
     30 from cycler import cycler
     31 import matplotlib
---> 32 import matplotlib.colorbar
     33 import matplotlib.image
     34 from matplotlib import rcsetup, style

~/opt/anaconda3/lib/python3.7/site-packages/matplotlib/colorbar.py in <module>
     25 
     26 import matplotlib as mpl
---> 27 import matplotlib.artist as martist
     28 import matplotlib.cbook as cbook
     29 import matplotlib.collections as collections

~/opt/anaconda3/lib/python3.7/site-packages/matplotlib/artist.py in <module>
     12 from . import cbook, docstring, rcParams
     13 from .path import Path
---> 14 from .transforms import (Bbox, IdentityTransform, Transform, TransformedBbox,
     15                          TransformedPatchPath, TransformedPath)
     16 

ImportError: cannot import name 'Bbox' from 'matplotlib.transforms' (/Users/hedyeherfani/opt/anaconda3/lib/python3.7/site-packages/matplotlib/transforms.py)

1 个答案:

答案 0 :(得分:0)

好像您使用的是matplotlib的旧版本。例如,version 0.91.2在transforms.py中没有Bbox类,但是大多数较新的版本都有。

  • 要确认这一点,请打开引用的文件/Users/hedyeherfani/opt/anaconda3/lib/python3.7/site-packages/matplotlib/transforms.py,然后检查class Bbox(BboxBase)或其他内容相似(需要定义一个称为Bbox的符号)

  • import matplotlib; matplotlib.__version__评估为Python解释器,以确定您的matplotlib版本。

  • 使用pip install matplotlib==<newversion> --upgrade

  • 之类的命令进行升级