我是编程的初学者,我正在开发一个使用ipython和jupyter笔记本的在线课程。我正在使用Mac OS 10.13.3。
我尝试按如下方式导入matplotlib,
import matplotlib.pyplot as plt
%matplotlib inline
但是,正在生成以下错误。
--------------------------
Traceback (most recent call last) <ipython-input-30-385145dcc870> in <module>()
----> 1 import matplotlib.pyplot as plt
2 get_ipython().magic(u'matplotlib inline')
/Users/Varshil/anaconda/envs/gl-env/lib/python2.7/site-packages/matplotlib/pyplot.py in <module>()
27 from cycler import cycler
28 import matplotlib
---> 29 import matplotlib.colorbar
30 from matplotlib import style
31 from matplotlib import _pylab_helpers, interactive
/Users/Varshil/anaconda/envs/gl-env/lib/python2.7/site-packages/matplotlib/colorbar.py in <module>()
30
31 import matplotlib as mpl
---> 32 import matplotlib.artist as martist
33 import matplotlib.cbook as cbook
34 import matplotlib.collections as collections
/Users/Varshil/anaconda/envs/gl-env/lib/python2.7/site-packages/matplotlib/artist.py in <module>()
9 import numpy as np
10 import matplotlib
---> 11 import matplotlib.cbook as cbook
12 from matplotlib.cbook import mplDeprecation
13 from matplotlib import docstring, rcParams
AttributeError: 'module' object has no attribute 'cbook'
如果有人可以帮助我解决这个问题,那将会很有帮助。我尝试过在线查询,但没有找到成功的潜在客户。
答案 0 :(得分:1)
这是因为您使用的是旧版本的matplotlib。
使用GraphLab Create的人,首先激活虚拟环境:
source gl-env/bin/activate
现在升级matplotlib:
pip install -U matplotlib
输出:
Found existing installation: matplotlib 1.5.1
Uninstalling matplotlib-1.5.1:
Successfully uninstalled matplotlib-1.5.1
Successfully installed matplotlib-2.1.2
重启iPython / Jupyter。
如果您使用的是Mac,则可能会收到以下错误:
RuntimeError: Python is not installed as a framework. The Mac OS X backend will not be able to function correctly if Python is not installed as a framework.
在那里创建一个〜/ .matplotlib / matplotlibrc文件并添加以下代码:backend: TkAgg
再次重启iPython / Jupyter。