Problem
在使用如下命令时出现 SyntaxError
报错,位置指向第二行的 %
import matplotlib
%matplotlib inline
google 之后在 github issure 上找到了一个 “解决方法”
from IPython import get_ipython
get_ipython().run_line_magic('matplotlib', 'inline')
但是继续报错
AttributeError: 'NoneType' object has no attribute 'run_line_magic'
Solvement
解决后分析,当时作者的 matplotlib
包可能存在如下问题
- 版本老旧
- 作为前置包,在安装某些包的同时安装了
matplotlib
(这些前置包可能存在问题) - 使用了错误的 conda 安装命令
因此可以直接尝试用 pip 更新/ 重装该包
pip upgrade matplotlib
pip uninstall matplotlib
pip install matplotlib
如仍有问题,欢迎留言