跳转到主要内容

JupyterLab代码片段扩展

项目描述

jupyterlab-snippets

Github Actions Status Version Conda Version Binder

JupyterLab 的代码片段扩展。

此扩展由名为 jupyterlab-snippets 的 Python 包组成,用于服务器扩展,以及名为 jupyterlab-snippets 的 NPM 包,用于前端扩展。

需求

  • JupyterLab >= 2.0
  • Node.js

安装

使用 conda

conda install -c conda-forge jupyterlab-snippets

使用 pip

pip install jupyterlab-snippets

如果您使用的是 JupyterLab 2.x,您将需要使用以下内容重新构建 JupyterLab:

jupyter lab build

使用方法

[jupyter_data_dir]/snippets 中添加代码片段(见:https://jupyter-docs.pythonlang.cn/en/latest/projects/jupyter-directories.html#id2

要查找 Jupyter 数据目录,请运行

$ jupyter --path

例如,在 macOS 上将显示以下列表

config:
    /Users/<username>/.jupyter
    ...
data:
    /Users/<username>/Library/Jupyter
    /Users/<username>/miniconda3/envs/<envname>/share/jupyter
    ...
runtime:
    ...

使用列在 data: 下的第一个目录来添加文件,这些文件将成为菜单中的代码片段。每个文件包含一个代码片段。目录可用于组织代码片段文件,并将成为菜单中的子菜单。

在 JupyterLab 中,使用 "代码片段" 菜单选择代码片段

Schermafbeelding 2020-03-30 om 17 25 31

将代码片段从 jupyter-boilerplate 格式转换

有关如何将代码片段从 jupyter-boilerplate 经典笔记本扩展(不适用于 JupyterLab)转换为 jupyterlab-snippets 的说明,请参阅 jupyter-boilerplate-converter

故障排除

如果您看到前端扩展但无法使用,请检查服务器扩展是否已启用

jupyter serverextension list

如果服务器扩展已安装并启用,但您看不到前端,请检查前端扩展是否已安装并启用

jupyter labextension list

如果已安装,请尝试

jupyter lab clean
jupyter lab build

开发安装

注意:您将需要 NodeJS 来构建扩展包。

jlpm 命令是 JupyterLab 随附的 yarn 的固定版本。您可以使用 yarnnpm 代替以下内容中的 jlpm

# Clone the repo to your local environment
# Change directory to the jupyterlab-snippets directory
# Install package in development mode
pip install -e .
# Link your development version of the extension with JupyterLab
jupyter labextension develop . --overwrite
# Rebuild extension Typescript source after making changes
jlpm run build

您可以在不同的终端中同时监视源目录并运行 JupyterLab,以监视扩展源代码的变化并自动重新构建扩展。

# Watch the source directory in one terminal, automatically rebuilding when needed
jlpm run watch
# Run JupyterLab in another terminal
jupyter lab

在监视命令运行时,每次保存的更改都将立即在本地上构建并可供运行的 JupyterLab 使用。刷新 JupyterLab 以在浏览器中加载更改(您可能需要等待几秒钟以重建扩展)。

默认情况下,jlpm run build 命令为该扩展生成源映射,以便更容易使用浏览器开发工具进行调试。要为 JupyterLab 核心扩展也生成源映射,可以运行以下命令

jupyter lab build --minimize=False

卸载

pip uninstall jupyterlab-snippets

项目详情


下载文件

下载适用于您的平台的文件。如果您不确定选择哪个,请了解有关 安装包 的更多信息。

源分发

jupyterlab-snippets-0.4.1.tar.gz (125.9 kB 查看散列)

上传时间

构建分发

jupyterlab_snippets-0.4.1-py3-none-any.whl (26.2 kB 查看散列)

上传时间 Python 3

支持