如何在 ipython 或 jupyter 笔记本中加载外部静态 Javascript 文件

2024-01-08

我试图在 ipython 笔记本中加载 d3 和 dimple.js 但它抛出错误。我也尝试过 require 但无法加载请为我提供一些解决方法


  1. 在笔记本中运行此命令以找出您的 jupyter 目录:

    from jupyter_core.paths import jupyter_config_dir
    jupyter_dir = jupyter_config_dir()
    jupyter_dir
    
  2. 在上面找到的 jupyter 目录下创建名为“custom”的文件夹 /风俗

  3. 在/custom/custom.js下创建custom.js文件并添加以下内容

    requirejs.config({
    paths: {
        d3: 'd3.min',
    }
    });
    
  4. 打开为您的个人资料创建的 jupyter_notebook_config.py。如果未创建,请使用以下命令从命令行/终端创建一个

    jupyter notebook --generate-config
    
  5. 修改 jupyter_notebook_config.py 中 js 文件夹的静态路径(从generate-config命令创建),如下所示

    c.NotebookApp.extra_static_paths = ["C:\your-js-folder"]
    
  6. 将外部 js 文件拖放到 C:\your-js-folder 下,然后停止并启动 jupyter Notebook

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何在 ipython 或 jupyter 笔记本中加载外部静态 Javascript 文件 的相关文章

随机推荐