You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用%matplotlib notebook时出现Javascript Error: IPython is not defined的问题求助

使用%matplotlib notebook时出现Javascript Error: IPython is not defined的问题求助

我一开始按常规流程导入库,准备启动交互式绘图会话:

# for viewing figures interactively
%matplotlib notebook
 
# To start plotting in matplotlib
import IPython
import matplotlib.pyplot as plt
import seaborn as sns
sns.set_style("whitegrid")

# Other data libraries
import numpy as np
import pandas as pd

# 3 dimensional plotting
from mpl_toolkits import mplot3d

# enable three-dimensional axes
fig = plt.figure()
ax = plt.axes(projection='3d')

结果运行后出现了这个错误:

Javascript Error: IPython is not defined

之后我查了些资料尝试其他方案,先安装了IPython Widgets:

pip install ipywidgets 
jupyter nbextension enable --py widgetsnbextension

现在把代码开头的%matplotlib notebook换成%matplotlib widgets,就能正常显示交互式图形了。

我还试了另一种方法:安装ipympl并启用对应的扩展:

pip install ipympl
jupyter nbextension enable --py --sys-prefix ipympl

之后把第一行换成%matplotlib ipympl,也能正常显示交互式图形。

但问题是,%matplotlib notebook这个魔法命令的错误依然存在。现在的方法只是绕开了错误让代码能运行,并没有真正解决问题——我还是完全搞不懂为什么JavaScript识别不了IPython。

有没有大佬能给点思路,真正解决这个问题?

备注:内容来源于stack exchange,提问作者Malihe Mahdavi sefat

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.14 17:15:28