生生不息

生生不息

报错Javascript Error: IPython is not defined解决

2025-07-01
报错Javascript Error: IPython is not defined解决

背景

最近学到backtrader回测,发现

# 可视化交易结果
cerebro.plot()
plt.show()

报错

Javascript Error: IPython is not defined

解决方案

因为notebook是7以上版本,不支持matlib的交互图

所以整体降级。新建一个conda环境

yaml文件如下

name: notebook
channels:
  - conda-forge
  - bioconda
dependencies:
  - python=3.10.4
  - snakemake=7.8.2
  - nbgrader=0.8.1
  - sqlalchemy=1.4.37
  - jinja2=3.1.2
  - nbconvert=6.5.0
  - jupyterhub=2.3.1
  - jupyter_server=1.17.1
  - notebook=6.4.12
  - nb_conda_kernels=2.5.2
  - numpy=1.22.4
  - matplotlib=3.5.1
  - pandas=1.4.2
  - scipy=1.8.1
  - seaborn=0.11.2
  - imageio=2.9.0
  - imageio-ffmpeg=0.4.7
  - scikit-image=0.19.2
  - scikit-learn=1.1.1
  - python-graphviz=0.20
  - nose=1.3.7
  - pip=22.1.2
  - biopython=1.79
  - requests=2.28.0
  - pyyaml=6.0
  - sympy=1.10.1
  - pytables=3.7.0
  - panel=0.13.0
  - hvplot=0.7.3
  - napari=0.4.12
  - pymc=4.2.2
  - filterpy=1.4.5
  - pip:
      - adskalman==0.3.11
      - dabest==0.3.1
      - figurefirst==0.0.6

保存为 notebook.yaml可以使用

conda env create -f notebook.yaml

创建环境

激活环境后使用 jupyter notebook

打开 localhost:8888

可以看到界面还是区别不同的。6.4.12的notebook完美不报错了。