CLI#

隐藏代码单元格内容

import atexit
import hashlib
import os
import pathlib
import pprint
import shutil
import tempfile

from IPython.display import *

RTD = os.environ.get("READTHEDOCS")

jupyter lite(或 jupyter-lite)CLI 提供了将以下各项结合在一起的生命周期工具:

  • 核心 JupyterLite 静态资源

  • 额外的 应用程序功能,如 Lab 扩展 和设置

  • 内核特定资源,如 Python wheel 文件

  • 用户创作内容,如 Notebook 文件

...整合到 可部署(并且可选 可重现)的 Jupyter 站点中,这些站点需要 HTTP 服务器,但不需要 应用程序 服务器。

安装#

!pip install jupyterlite-core
!jupyter lite --version
Requirement already satisfied: jupyterlite-core in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (0.6.4)
Requirement already satisfied: doit<1,>=0.34 in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from jupyterlite-core) (0.36.0)
Requirement already satisfied: jupyter-core>=4.7 in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from jupyterlite-core) (5.8.1)
Requirement already satisfied: cloudpickle in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from doit<1,>=0.34->jupyterlite-core) (3.1.1)
Requirement already satisfied: importlib-metadata>=4.4 in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from doit<1,>=0.34->jupyterlite-core) (8.7.0)
Requirement already satisfied: zipp>=3.20 in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from importlib-metadata>=4.4->doit<1,>=0.34->jupyterlite-core) (3.23.0)
Requirement already satisfied: platformdirs>=2.5 in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from jupyter-core>=4.7->jupyterlite-core) (4.3.8)
Requirement already satisfied: traitlets>=5.3 in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from jupyter-core>=4.7->jupyterlite-core) (5.14.3)
0.6.4

附加组件依赖项#

不同 附加组件 的某些额外功能具有额外的依赖项。

pip install jupyterlite-core[contents] # jupyter_server for contents API indexing
pip install jupyterlite-core[serve]    # tornado for better local previewing with `serve`
pip install jupyterlite-core[check]    # validate more data with jsonschema
pip install jupyterlite-core[lab]      # a known-compatible jupyterlab (entails `contents`, `serve`, `check`)

...或者,针对所有功能

pip install jupyterlite-core[all]      # all of the above!
!pip install jupyterlite-core[all]

隐藏代码单元格输出

Requirement already satisfied: jupyterlite-core[all] in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (0.6.4)
Requirement already satisfied: doit<1,>=0.34 in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from jupyterlite-core[all]) (0.36.0)
Requirement already satisfied: jupyter-core>=4.7 in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from jupyterlite-core[all]) (5.8.1)
Requirement already satisfied: jsonschema>=3 in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from jupyterlite-core[all]) (4.25.0)
Requirement already satisfied: jupyter-server in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from jupyterlite-core[all]) (2.16.0)
Requirement already satisfied: jupyterlab-server<3,>=2.8.1 in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from jupyterlite-core[all]) (2.27.3)
Requirement already satisfied: jupyterlab<4.5,>=4.4.5 in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from jupyterlite-core[all]) (4.4.5)
Requirement already satisfied: libarchive-c>=4.0 in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from jupyterlite-core[all]) (5.3)
Requirement already satisfied: notebook<7.5,>=7.4.5 in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from jupyterlite-core[all]) (7.4.5)
Requirement already satisfied: pkginfo in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from jupyterlite-core[all]) (1.12.1.2)
Requirement already satisfied: tornado>=6.1 in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from jupyterlite-core[all]) (6.5.1)
Requirement already satisfied: cloudpickle in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from doit<1,>=0.34->jupyterlite-core[all]) (3.1.1)
Requirement already satisfied: importlib-metadata>=4.4 in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from doit<1,>=0.34->jupyterlite-core[all]) (8.7.0)
Requirement already satisfied: async-lru>=1.0.0 in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from jupyterlab<4.5,>=4.4.5->jupyterlite-core[all]) (2.0.5)
Requirement already satisfied: httpx>=0.25.0 in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from jupyterlab<4.5,>=4.4.5->jupyterlite-core[all]) (0.28.1)
Requirement already satisfied: ipykernel>=6.5.0 in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from jupyterlab<4.5,>=4.4.5->jupyterlite-core[all]) (6.30.1)
Requirement already satisfied: jinja2>=3.0.3 in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from jupyterlab<4.5,>=4.4.5->jupyterlite-core[all]) (3.1.6)
Requirement already satisfied: jupyter-lsp>=2.0.0 in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from jupyterlab<4.5,>=4.4.5->jupyterlite-core[all]) (2.2.6)
Requirement already satisfied: notebook-shim>=0.2 in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from jupyterlab<4.5,>=4.4.5->jupyterlite-core[all]) (0.2.4)
Requirement already satisfied: packaging in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from jupyterlab<4.5,>=4.4.5->jupyterlite-core[all]) (25.0)
Requirement already satisfied: setuptools>=41.1.0 in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from jupyterlab<4.5,>=4.4.5->jupyterlite-core[all]) (80.9.0)
Requirement already satisfied: traitlets in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from jupyterlab<4.5,>=4.4.5->jupyterlite-core[all]) (5.14.3)
Requirement already satisfied: anyio>=3.1.0 in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from jupyter-server->jupyterlite-core[all]) (4.10.0)
Requirement already satisfied: argon2-cffi>=21.1 in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from jupyter-server->jupyterlite-core[all]) (25.1.0)
Requirement already satisfied: jupyter-client>=7.4.4 in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from jupyter-server->jupyterlite-core[all]) (8.6.3)
Requirement already satisfied: jupyter-events>=0.11.0 in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from jupyter-server->jupyterlite-core[all]) (0.12.0)
Requirement already satisfied: jupyter-server-terminals>=0.4.4 in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from jupyter-server->jupyterlite-core[all]) (0.5.3)
Requirement already satisfied: nbconvert>=6.4.4 in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from jupyter-server->jupyterlite-core[all]) (7.16.6)
Requirement already satisfied: nbformat>=5.3.0 in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from jupyter-server->jupyterlite-core[all]) (5.10.4)
Requirement already satisfied: overrides>=5.0 in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from jupyter-server->jupyterlite-core[all]) (7.7.0)
Requirement already satisfied: prometheus-client>=0.9 in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from jupyter-server->jupyterlite-core[all]) (0.22.1)
Requirement already satisfied: pyzmq>=24 in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from jupyter-server->jupyterlite-core[all]) (27.0.1)
Requirement already satisfied: send2trash>=1.8.2 in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from jupyter-server->jupyterlite-core[all]) (1.8.3)
Requirement already satisfied: terminado>=0.8.3 in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from jupyter-server->jupyterlite-core[all]) (0.18.1)
Requirement already satisfied: websocket-client>=1.7 in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from jupyter-server->jupyterlite-core[all]) (1.8.0)
Requirement already satisfied: babel>=2.10 in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from jupyterlab-server<3,>=2.8.1->jupyterlite-core[all]) (2.17.0)
Requirement already satisfied: json5>=0.9.0 in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from jupyterlab-server<3,>=2.8.1->jupyterlite-core[all]) (0.12.0)
Requirement already satisfied: requests>=2.31 in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from jupyterlab-server<3,>=2.8.1->jupyterlite-core[all]) (2.32.4)
Requirement already satisfied: idna>=2.8 in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from anyio>=3.1.0->jupyter-server->jupyterlite-core[all]) (3.10)
Requirement already satisfied: sniffio>=1.1 in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from anyio>=3.1.0->jupyter-server->jupyterlite-core[all]) (1.3.1)
Requirement already satisfied: typing_extensions>=4.5 in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from anyio>=3.1.0->jupyter-server->jupyterlite-core[all]) (4.14.1)
Requirement already satisfied: argon2-cffi-bindings in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from argon2-cffi>=21.1->jupyter-server->jupyterlite-core[all]) (25.1.0)
Requirement already satisfied: certifi in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from httpx>=0.25.0->jupyterlab<4.5,>=4.4.5->jupyterlite-core[all]) (2025.8.3)
Requirement already satisfied: httpcore==1.* in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from httpx>=0.25.0->jupyterlab<4.5,>=4.4.5->jupyterlite-core[all]) (1.0.9)
Requirement already satisfied: h11>=0.16 in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from httpcore==1.*->httpx>=0.25.0->jupyterlab<4.5,>=4.4.5->jupyterlite-core[all]) (0.16.0)
Requirement already satisfied: zipp>=3.20 in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from importlib-metadata>=4.4->doit<1,>=0.34->jupyterlite-core[all]) (3.23.0)
Requirement already satisfied: comm>=0.1.1 in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from ipykernel>=6.5.0->jupyterlab<4.5,>=4.4.5->jupyterlite-core[all]) (0.2.3)
Requirement already satisfied: debugpy>=1.6.5 in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from ipykernel>=6.5.0->jupyterlab<4.5,>=4.4.5->jupyterlite-core[all]) (1.8.16)
Requirement already satisfied: ipython>=7.23.1 in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from ipykernel>=6.5.0->jupyterlab<4.5,>=4.4.5->jupyterlite-core[all]) (9.4.0)
Requirement already satisfied: matplotlib-inline>=0.1 in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from ipykernel>=6.5.0->jupyterlab<4.5,>=4.4.5->jupyterlite-core[all]) (0.1.7)
Requirement already satisfied: nest-asyncio>=1.4 in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from ipykernel>=6.5.0->jupyterlab<4.5,>=4.4.5->jupyterlite-core[all]) (1.6.0)
Requirement already satisfied: psutil>=5.7 in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from ipykernel>=6.5.0->jupyterlab<4.5,>=4.4.5->jupyterlite-core[all]) (7.0.0)
Requirement already satisfied: decorator in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from ipython>=7.23.1->ipykernel>=6.5.0->jupyterlab<4.5,>=4.4.5->jupyterlite-core[all]) (5.2.1)
Requirement already satisfied: ipython-pygments-lexers in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from ipython>=7.23.1->ipykernel>=6.5.0->jupyterlab<4.5,>=4.4.5->jupyterlite-core[all]) (1.1.1)
Requirement already satisfied: jedi>=0.16 in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from ipython>=7.23.1->ipykernel>=6.5.0->jupyterlab<4.5,>=4.4.5->jupyterlite-core[all]) (0.19.2)
Requirement already satisfied: pexpect>4.3 in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from ipython>=7.23.1->ipykernel>=6.5.0->jupyterlab<4.5,>=4.4.5->jupyterlite-core[all]) (4.9.0)
Requirement already satisfied: prompt_toolkit<3.1.0,>=3.0.41 in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from ipython>=7.23.1->ipykernel>=6.5.0->jupyterlab<4.5,>=4.4.5->jupyterlite-core[all]) (3.0.51)
Requirement already satisfied: pygments>=2.4.0 in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from ipython>=7.23.1->ipykernel>=6.5.0->jupyterlab<4.5,>=4.4.5->jupyterlite-core[all]) (2.19.2)
Requirement already satisfied: stack_data in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from ipython>=7.23.1->ipykernel>=6.5.0->jupyterlab<4.5,>=4.4.5->jupyterlite-core[all]) (0.6.3)
Requirement already satisfied: wcwidth in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from prompt_toolkit<3.1.0,>=3.0.41->ipython>=7.23.1->ipykernel>=6.5.0->jupyterlab<4.5,>=4.4.5->jupyterlite-core[all]) (0.2.13)
Requirement already satisfied: parso<0.9.0,>=0.8.4 in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from jedi>=0.16->ipython>=7.23.1->ipykernel>=6.5.0->jupyterlab<4.5,>=4.4.5->jupyterlite-core[all]) (0.8.4)
Requirement already satisfied: MarkupSafe>=2.0 in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from jinja2>=3.0.3->jupyterlab<4.5,>=4.4.5->jupyterlite-core[all]) (3.0.2)
Requirement already satisfied: attrs>=22.2.0 in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from jsonschema>=3->jupyterlite-core[all]) (25.3.0)
Requirement already satisfied: jsonschema-specifications>=2023.03.6 in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from jsonschema>=3->jupyterlite-core[all]) (2025.4.1)
Requirement already satisfied: referencing>=0.28.4 in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from jsonschema>=3->jupyterlite-core[all]) (0.36.2)
Requirement already satisfied: rpds-py>=0.7.1 in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from jsonschema>=3->jupyterlite-core[all]) (0.27.0)
Requirement already satisfied: python-dateutil>=2.8.2 in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from jupyter-client>=7.4.4->jupyter-server->jupyterlite-core[all]) (2.9.0.post0)
Requirement already satisfied: platformdirs>=2.5 in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from jupyter-core>=4.7->jupyterlite-core[all]) (4.3.8)
Requirement already satisfied: python-json-logger>=2.0.4 in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from jupyter-events>=0.11.0->jupyter-server->jupyterlite-core[all]) (2.0.7)
Requirement already satisfied: pyyaml>=5.3 in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from jupyter-events>=0.11.0->jupyter-server->jupyterlite-core[all]) (6.0.2)
Requirement already satisfied: rfc3339-validator in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from jupyter-events>=0.11.0->jupyter-server->jupyterlite-core[all]) (0.1.4)
Requirement already satisfied: rfc3986-validator>=0.1.1 in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from jupyter-events>=0.11.0->jupyter-server->jupyterlite-core[all]) (0.1.1)
Requirement already satisfied: fqdn in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from jsonschema[format-nongpl]>=4.18.0->jupyter-events>=0.11.0->jupyter-server->jupyterlite-core[all]) (1.5.1)
Requirement already satisfied: isoduration in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from jsonschema[format-nongpl]>=4.18.0->jupyter-events>=0.11.0->jupyter-server->jupyterlite-core[all]) (20.11.0)
Requirement already satisfied: jsonpointer>1.13 in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from jsonschema[format-nongpl]>=4.18.0->jupyter-events>=0.11.0->jupyter-server->jupyterlite-core[all]) (3.0.0)
Requirement already satisfied: rfc3987-syntax>=1.1.0 in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from jsonschema[format-nongpl]>=4.18.0->jupyter-events>=0.11.0->jupyter-server->jupyterlite-core[all]) (1.1.0)
Requirement already satisfied: uri-template in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from jsonschema[format-nongpl]>=4.18.0->jupyter-events>=0.11.0->jupyter-server->jupyterlite-core[all]) (1.3.0)
Requirement already satisfied: webcolors>=24.6.0 in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from jsonschema[format-nongpl]>=4.18.0->jupyter-events>=0.11.0->jupyter-server->jupyterlite-core[all]) (24.11.1)
Requirement already satisfied: beautifulsoup4 in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from nbconvert>=6.4.4->jupyter-server->jupyterlite-core[all]) (4.13.4)
Requirement already satisfied: bleach!=5.0.0 in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from bleach[css]!=5.0.0->nbconvert>=6.4.4->jupyter-server->jupyterlite-core[all]) (6.2.0)
Requirement already satisfied: defusedxml in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from nbconvert>=6.4.4->jupyter-server->jupyterlite-core[all]) (0.7.1)
Requirement already satisfied: jupyterlab-pygments in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from nbconvert>=6.4.4->jupyter-server->jupyterlite-core[all]) (0.3.0)
Requirement already satisfied: mistune<4,>=2.0.3 in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from nbconvert>=6.4.4->jupyter-server->jupyterlite-core[all]) (3.1.3)
Requirement already satisfied: nbclient>=0.5.0 in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from nbconvert>=6.4.4->jupyter-server->jupyterlite-core[all]) (0.10.2)
Requirement already satisfied: pandocfilters>=1.4.1 in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from nbconvert>=6.4.4->jupyter-server->jupyterlite-core[all]) (1.5.0)
Requirement already satisfied: webencodings in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from bleach!=5.0.0->bleach[css]!=5.0.0->nbconvert>=6.4.4->jupyter-server->jupyterlite-core[all]) (0.5.1)
Requirement already satisfied: tinycss2<1.5,>=1.1.0 in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from bleach[css]!=5.0.0->nbconvert>=6.4.4->jupyter-server->jupyterlite-core[all]) (1.4.0)
Requirement already satisfied: fastjsonschema>=2.15 in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from nbformat>=5.3.0->jupyter-server->jupyterlite-core[all]) (2.21.1)
Requirement already satisfied: ptyprocess>=0.5 in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from pexpect>4.3->ipython>=7.23.1->ipykernel>=6.5.0->jupyterlab<4.5,>=4.4.5->jupyterlite-core[all]) (0.7.0)
Requirement already satisfied: six>=1.5 in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from python-dateutil>=2.8.2->jupyter-client>=7.4.4->jupyter-server->jupyterlite-core[all]) (1.17.0)
Requirement already satisfied: charset_normalizer<4,>=2 in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from requests>=2.31->jupyterlab-server<3,>=2.8.1->jupyterlite-core[all]) (3.4.2)
Requirement already satisfied: urllib3<3,>=1.21.1 in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from requests>=2.31->jupyterlab-server<3,>=2.8.1->jupyterlite-core[all]) (2.5.0)
Requirement already satisfied: lark>=1.2.2 in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from rfc3987-syntax>=1.1.0->jsonschema[format-nongpl]>=4.18.0->jupyter-events>=0.11.0->jupyter-server->jupyterlite-core[all]) (1.2.2)
Requirement already satisfied: cffi>=1.0.1 in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from argon2-cffi-bindings->argon2-cffi>=21.1->jupyter-server->jupyterlite-core[all]) (1.17.1)
Requirement already satisfied: pycparser in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from cffi>=1.0.1->argon2-cffi-bindings->argon2-cffi>=21.1->jupyter-server->jupyterlite-core[all]) (2.22)
Requirement already satisfied: soupsieve>1.2 in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from beautifulsoup4->nbconvert>=6.4.4->jupyter-server->jupyterlite-core[all]) (2.7)
Requirement already satisfied: arrow>=0.15.0 in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from isoduration->jsonschema[format-nongpl]>=4.18.0->jupyter-events>=0.11.0->jupyter-server->jupyterlite-core[all]) (1.3.0)
Requirement already satisfied: types-python-dateutil>=2.8.10 in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from arrow>=0.15.0->isoduration->jsonschema[format-nongpl]>=4.18.0->jupyter-events>=0.11.0->jupyter-server->jupyterlite-core[all]) (2.9.0.20250708)
Requirement already satisfied: executing>=1.2.0 in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from stack_data->ipython>=7.23.1->ipykernel>=6.5.0->jupyterlab<4.5,>=4.4.5->jupyterlite-core[all]) (2.2.0)
Requirement already satisfied: asttokens>=2.1.0 in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from stack_data->ipython>=7.23.1->ipykernel>=6.5.0->jupyterlab<4.5,>=4.4.5->jupyterlite-core[all]) (3.0.0)
Requirement already satisfied: pure_eval in /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/stable/lib/python3.12/site-packages (from stack_data->ipython>=7.23.1->ipykernel>=6.5.0->jupyterlab<4.5,>=4.4.5->jupyterlite-core[all]) (0.2.3)

安装内核#

jupyterlite-core 包提供了构建 JupyterLite 网站的核心功能,默认不安装任何内核。

如果您想在 JupyterLite 部署中包含内核,则需要在构建站点之前安装它。

例如,要同时包含基于 Pyodide 的 Python 内核

pip install jupyterlite-pyodide-kernel

快速入门#

安装后,可以通过以下方式访问本地托管的空 JupyterLite 站点:

jupyter lite serve

这将

  • init 初始化基线资产

  • build 构建所有额外资产

    • 如果找到 files/ 文件夹,这些文件将被复制到 _output/files

      • ... 并且如果安装了 jupyter_server,则会进行 索引

  • serve 本地服务站点并打印 URL

Lite 目录#

当您运行 jupyter lite 命令时,它假定您的当前工作目录是 JupyterLite 站点的一部分内容。您可以使用 --lite-dir 覆盖此设置。默认情况下,构建的站点将创建在 _output 中,但可以使用 --output-dir 覆盖。

隐藏代码单元格内容

if "TMP_DIR" not in globals():
    TMP_DIR = pathlib.Path(tempfile.mkdtemp(prefix="_my_lite_dir_"))

    def clean():
        shutil.rmtree(TMP_DIR)

    atexit.register(clean)
os.chdir(TMP_DIR)
print(pathlib.Path.cwd())
/tmp/_my_lite_dir_monrxeo_

知名文件#

您的 --lite-dir 中的一些具有特殊含义的文件

查找路径...

... 查找名为

... 如果找到

.
./lab
./notebook

jupyter-lite.{json,ipynb}

_output/{path}/jupyter-lite.{json,ipynb} 中的静态文件合并

.
./lab
./notebook

overrides.json

_output/{*}/jupyter-lite.json 中的静态文件合并

./files/

*

逐字复制到 _output/files/* 并在 /api/contents 中索引

./pypi/

*.whl

逐字复制到 _output/pypi/* 并索引

./static/pyodide

pyodide.js, *.data, *.js

逐字复制到 _output/pyodide/*

有关合并内容的更多信息。

用法#

常见参数#

所有以下参数都在 jupyter_lite_config.json#LiteBuildConfig 中配置。

参数

描述

default

环境变量

--lite-dir

站点的配置和内容

当前工作目录

JUPYTERLITE_DIR

--output-dir

将创建可托管站点的位置

_output

JUPYTERLITE_OUTPUT_DIR

--cache-dir

下载的缓存目录

<lite_dir>/.cache

JUPYTERLITE_CACHE_DIR

--disable-addons

按入口点名称禁用特定附加组件

--app-archive

基于的替代站点

捆绑

--contents

要复制到 _output/files/ 并作为 内容 可用的目录

./files

--ignore-contents

绝不 应包含在 /files/ 中的模式(即使在 lite-dir 中找到)

各种

--extra-ignore-contents

绝不 应包含在 /files/ 中的附加模式(即使在 lite-dir 中找到)

--output-archive

存档的路径

<directory>-jupyterlite.tgz

JUPYTERLAB_OUTPUT_ARCHIVE

--port

127.0.0.1 上服务测试服务器的端口

8000

JUPYTERLITE_PORT

--base-url

包含在站点之前的 URL 前缀

/

JUPYTERLITE_BASE_URL

--source-date-epoch

可选启用额外的可重现构建措施(尽力而为!)

SOURCE_DATE_EPOCH

--federated-extensions

包含扩展的文件夹、pip/conda 包的路径 参见注释

--ignore-sys-prefix

不要从 sys.prefix 复制任何内容,例如安装的 lab 扩展

False

--settings-overrides

要启用的附加设置覆盖

附加组件配置#

一些构建时附加组件提供了自己的 CLI 标志和可配置值。这些也可能在 jupyter-lite.json 中配置运行时选项。

PyodideAddon#

参数

描述

default

环境变量

--pyodide

pyodide 发行版(或 .bz2 存档)的路径或 URL

JUPYTERLITE_PYODIDE_URL

PipliteAddon#

参数

描述

default

环境变量

--piplite-wheels

在运行时可供 pyodide 内核使用的额外 wheel 文件

所有参数都可以通过 jupyter lite 启动目录中的 jupyter_lite_config.json 进行配置,或者通过 --config 提供。

提示

有关高级示例,请参阅本文档使用的配置

帮助#

CLI 提供了自己的文档,在 --help(或 -h)下。

!jupyter lite --help

隐藏代码单元格输出

A Jupyter Application

Subcommands
===========
Subcommands are launched as `jupyter cmd [args]`. For information on using
subcommand 'cmd', do: `jupyter cmd -h`.

list
    describe a JupyterLite site
status
    report about what a JupyterLite build _might_ do
init
    initialize a JupyterLite site from an app archive baseline
build
    build a JupyterLite site, including user content
check
    verify a JupyterLite site, using available schema and rules
serve
    serve a JupyterLite site, using best available HTTP server
archive
    build a JupyterLite app archive, which can be used as a baseline
doit
    use the full doit CLI, see https://pydoit.org/contents.html

Options
=======
The options below are convenience aliases to configurable class-options,
as listed in the "Equivalent to" description-line of the aliases.
To see all configurable class-options for some <cmd>, use:
    <cmd> --help-all

--debug
    set log level to logging.DEBUG (maximize logging output)
    Equivalent to: [--Application.log_level=10]
-y
    Answer yes to any questions instead of prompting.
    Equivalent to: [--JupyterApp.answer_yes=True]
--ignore-sys-prefix
    Do not copy anything from sys.prefix
    Equivalent to: [--LiteBuildConfig.ignore_sys_prefix=True]
--no-sourcemaps
    Strip all sourcemaps from applications and extensions
    Equivalent to: [--LiteBuildConfig.no_sourcemaps=True]
--no-unused-shared-packages
    Remove shared packages not used by --apps
    Equivalent to: [--LiteBuildConfig.no_unused_shared_packages=True]
--no-libarchive
    Do not try to use libarchive-c for archive operations
    Equivalent to: [--LiteBuildConfig.no_libarchive=True]
--log-level=<Enum>
    Set the log level by value or name.
    Choices: any of [0, 10, 20, 30, 40, 50, 'DEBUG', 'INFO', 'WARN', 'ERROR', 'CRITICAL']
    Default: 30
    Equivalent to: [--Application.log_level]
--config=<Unicode>
    Full path of a config file.
    Default: ''
    Equivalent to: [--JupyterApp.config_file]
--disable-addons=<typedtuple-item-1>...
    skip loading `entry_point` for these addons. TODO: should be a dict
    Default: ()
    Equivalent to: [--LiteBuildConfig.disable_addons]
--app-archive=<CPath>
    The app archive to use. env: JUPYTERLITE_APP_ARCHIVE
    Default: traitlets.Undefined
    Equivalent to: [--LiteBuildConfig.app_archive]
--apps=<typedtuple-item-1>...
    the Lite apps to explicitly include in build e.g. lab, tree, repl
    Default: ()
    Equivalent to: [--LiteBuildConfig.apps]
--lite-dir=<CPath>
    The root folder of a JupyterLite project. env: JUPYTERLITE_DIR
    Default: traitlets.Undefined
    Equivalent to: [--LiteBuildConfig.lite_dir]
--contents=<typedtuple-item-1>...
    Contents to add and index
    Default: ()
    Equivalent to: [--LiteBuildConfig.contents]
--ignore-contents=<tuple-item-1>...
    Path regular expressions that should never be included as contents
    Default: ()
    Equivalent to: [--LiteBuildConfig.ignore_contents]
--extra-ignore-contents=<tuple-item-1>...
    Additional path regular expressions that should never be included as
    contents
    Default: ()
    Equivalent to: [--LiteBuildConfig.extra_ignore_contents]
--settings-overrides=<typedtuple-item-1>...
    Specific overrides.json to include
    Default: ()
    Equivalent to: [--LiteBuildConfig.settings_overrides]
--output-dir=<CPath>
    Where to build the JupyterLite site. env: JUPYTERLITE_OUTPUT_DIR
    Default: traitlets.Undefined
    Equivalent to: [--LiteBuildConfig.output_dir]
--output-archive=<CPath>
    Archive to create. env: JUPYTERLITE_OUTPUT_ARCHIVE
    Default: traitlets.Undefined
    Equivalent to: [--LiteBuildConfig.output_archive]
--source-date-epoch=<CInt>
    Trigger reproducible builds, clamping timestamps to this value
    Default: 0
    Equivalent to: [--LiteBuildConfig.source_date_epoch]
--port=<CInt>
    [serve] the port to (insecurely) expose on http://127.0.0.1. env:
    JUPYTERLITE_PORT
    Default: 0
    Equivalent to: [--LiteBuildConfig.port]
--base-url=<Unicode>
    [serve] the prefix to use. env: JUPYTERLITE_BASE_URL
    Default: ''
    Equivalent to: [--LiteBuildConfig.base_url]

To see all available configurables, use `--help-all`.

状态#

此命令始终可以安全运行,它提供了 JupyterLite 正在做什么的概述。

!jupyter lite status

隐藏代码单元格输出

static:jupyter-lite.json
.  pre_status:static:jupyter-lite.json
    tarball:         jupyterlite-app-0.6.4.tgz 15MB
    output:          /tmp/_my_lite_dir_monrxeo_/_output
    lite dir:        /tmp/_my_lite_dir_monrxeo_
    apps:            
    sourcemaps:      True
    unused packages: True
archive:archive
contents:contents
icons:icons
lite:jupyter-lite.json
mimetypes:jupyter-lite.json
serve:contents
settings:overrides
translation:translation
.  status:archive:archive
[LiteStatusApp] No archive (yet): _my_lite_dir_monrxeo_-jupyterlite.tgz
.  status:contents:contents
    contents: 0 files
.  status:icons:icons
    favicon files: 0 files
.  status:lite:jupyter-lite.json
[LiteStatusApp]     jupyter-lite.(json|ipynb): 0 files
.  status:mimetypes:jupyter-lite.json
    filetypes:         26 
.  status:serve:contents
    url: http://127.0.0.1:8000/
    server: tornado
    headers:
.  status:settings:overrides
    overrides.json: 0
.  status:translation:translation
    translation files: 0 files

列表#

此命令始终可以安全运行,它提供了 JupyterLite 可能 会做什么的概述。

TODO: 改进默认输出

!jupyter lite list

隐藏代码单元格输出

static:jupyter-lite.json
archive:archive
contents:contents
icons:icons
lite:jupyter-lite.json
mimetypes:jupyter-lite.json
serve:contents
settings:overrides
translation:translation
static:output_dir
static:unpack
federated_extensions:copy:ext:jupyterlab_pygments
federated_extensions:copy:ext:@jupyter-notebook/lab-extension
icons:copy
translation:copy
federated_extensions:patch
mimetypes:patch
serve:tornado
report:SHA256SUMS
archive:archive:_my_lite_dir_monrxeo_-jupyterlite.tgz
R archive                                                                   
R archive:archive:archive:_my_lite_dir_monrxeo_-jupyterlite.tgz             generate a new app archive
R build                                                                     
R build:icons:copy                                                          copy the favicons
R build:translation:copy                                                    create the translation data
R check                                                                     
R init                                                                      
R init:static:unpack                                                        unpack a 'gold master' JupyterLite from jupyterlite-app-0.6.4.tgz
R post_archive                                                              
R post_build                                                                
E post_build:federated_extensions:patch                                     ensure jupyter-lite.json includes the federated_extensions
R post_build:mimetypes:patch                                                ensure /tmp/_my_lite_dir_monrxeo_/_output/jupyter-lite.json includes the file_types
R post_check                                                                
R post_init                                                                 
R post_serve                                                                
R post_status                                                               
R pre_archive                                                               
R pre_archive:report:SHA256SUMS                                             hash all of the files
R pre_build                                                                 
R pre_build:federated_extensions:copy:ext:@jupyter-notebook/lab-extension   
R pre_build:federated_extensions:copy:ext:jupyterlab_pygments               
R pre_check                                                                 
R pre_init                                                                  
R pre_init:static:output_dir                                                clean out the lite directory
R pre_serve                                                                 
R pre_status                                                                
R pre_status:static:jupyter-lite.json                                       
R serve                                                                     
R serve:serve:tornado                                                       run server at http://127.0.0.1:8000/ for /tmp/_my_lite_dir_monrxeo_/_output
R status                                                                    
R status:archive:archive                                                    
R status:contents:contents                                                  
R status:icons:icons                                                        
R status:lite:jupyter-lite.json                                             
R status:mimetypes:jupyter-lite.json                                        
R status:serve:contents                                                     
R status:settings:overrides                                                 
R status:translation:translation                                            

初始化#

将所有静态数据复制到 --output-dir

!jupyter lite init

隐藏代码单元格输出

static:jupyter-lite.json
.  pre_status:static:jupyter-lite.json
    tarball:         jupyterlite-app-0.6.4.tgz 15MB
    output:          /tmp/_my_lite_dir_monrxeo_/_output
    lite dir:        /tmp/_my_lite_dir_monrxeo_
    apps:            
    sourcemaps:      True
    unused packages: True
archive:archive
contents:contents
icons:icons
lite:jupyter-lite.json
mimetypes:jupyter-lite.json
serve:contents
settings:overrides
translation:translation
.  status:archive:archive
[LiteInitApp] No archive (yet): _my_lite_dir_monrxeo_-jupyterlite.tgz
.  status:contents:contents
    contents: 0 files
.  status:icons:icons
    favicon files: 0 files
.  status:lite:jupyter-lite.json
[LiteInitApp]     jupyter-lite.(json|ipynb): 0 files
.  status:mimetypes:jupyter-lite.json
    filetypes:         26 
.  status:serve:contents
    url: http://127.0.0.1:8000/
    server: tornado
    headers:
.  status:settings:overrides
    overrides.json: 0
.  status:translation:translation
    translation files: 0 files
static:output_dir
.  pre_init:static:output_dir
static:unpack
.  init:static:unpack

构建#

将所有 用户创作内容 复制到 --output-dir,并应用适当的更改,例如生成的 Contents API 响应。

特殊的知名文件将进行适当的 合并,但通常,用户目录中存在的文件将覆盖任何现有内容。

!jupyter lite build

隐藏代码单元格输出

static:jupyter-lite.json
.  pre_status:static:jupyter-lite.json
    tarball:         jupyterlite-app-0.6.4.tgz 15MB
    output:          /tmp/_my_lite_dir_monrxeo_/_output
    lite dir:        /tmp/_my_lite_dir_monrxeo_
    apps:            
    sourcemaps:      True
    unused packages: True
archive:archive
contents:contents
icons:icons
lite:jupyter-lite.json
mimetypes:jupyter-lite.json
serve:contents
settings:overrides
translation:translation
.  status:archive:archive
[LiteBuildApp] No archive (yet): _my_lite_dir_monrxeo_-jupyterlite.tgz
.  status:contents:contents
    contents: 0 files
.  status:icons:icons
    favicon files: 0 files
.  status:lite:jupyter-lite.json
[LiteBuildApp]     jupyter-lite.(json|ipynb): 0 files
.  status:mimetypes:jupyter-lite.json
    filetypes:         26 
.  status:serve:contents
    url: http://127.0.0.1:8000/
    server: tornado
    headers:
.  status:settings:overrides
    overrides.json: 0
.  status:translation:translation
    translation files: 0 files
static:output_dir
-- pre_init:static:output_dir
static:unpack
-- init:static:unpack
federated_extensions:copy:ext:jupyterlab_pygments
federated_extensions:copy:ext:@jupyter-notebook/lab-extension
.  pre_build:federated_extensions:copy:ext:jupyterlab_pygments
.  pre_build:federated_extensions:copy:ext:@jupyter-notebook/lab-extension
icons:copy
translation:copy
.  build:icons:copy
.  build:translation:copy
federated_extensions:patch
federated_extensions:settings
mimetypes:patch
.  post_build:federated_extensions:patch
.  post_build:federated_extensions:settings
.  post_build:mimetypes:patch

服务#

http://127.0.0.1:{--port=8000}{--base-url=/} 上服务 --output-dir

警告

不是 生产服务器。在尝试将其变为其他用途之前,请考虑 任何 部署选项。

!jupyter lite serve --help

隐藏代码单元格输出

A Jupyter Application

Options
=======
The options below are convenience aliases to configurable class-options,
as listed in the "Equivalent to" description-line of the aliases.
To see all configurable class-options for some <cmd>, use:
    <cmd> --help-all

--debug
    set log level to logging.DEBUG (maximize logging output)
    Equivalent to: [--Application.log_level=10]
-y
    Answer yes to any questions instead of prompting.
    Equivalent to: [--JupyterApp.answer_yes=True]
--ignore-sys-prefix
    Do not copy anything from sys.prefix
    Equivalent to: [--LiteBuildConfig.ignore_sys_prefix=True]
--no-sourcemaps
    Strip all sourcemaps from applications and extensions
    Equivalent to: [--LiteBuildConfig.no_sourcemaps=True]
--no-unused-shared-packages
    Remove shared packages not used by --apps
    Equivalent to: [--LiteBuildConfig.no_unused_shared_packages=True]
--no-libarchive
    Do not try to use libarchive-c for archive operations
    Equivalent to: [--LiteBuildConfig.no_libarchive=True]
--force
    forget previous runs of task and re-run from the beginning
    Equivalent to: [--LiteTaskApp.force=True]
--log-level=<Enum>
    Set the log level by value or name.
    Choices: any of [0, 10, 20, 30, 40, 50, 'DEBUG', 'INFO', 'WARN', 'ERROR', 'CRITICAL']
    Default: 30
    Equivalent to: [--Application.log_level]
--config=<Unicode>
    Full path of a config file.
    Default: ''
    Equivalent to: [--JupyterApp.config_file]
--disable-addons=<typedtuple-item-1>...
    skip loading `entry_point` for these addons. TODO: should be a dict
    Default: ()
    Equivalent to: [--LiteBuildConfig.disable_addons]
--app-archive=<CPath>
    The app archive to use. env: JUPYTERLITE_APP_ARCHIVE
    Default: traitlets.Undefined
    Equivalent to: [--LiteBuildConfig.app_archive]
--apps=<typedtuple-item-1>...
    the Lite apps to explicitly include in build e.g. lab, tree, repl
    Default: ()
    Equivalent to: [--LiteBuildConfig.apps]
--lite-dir=<CPath>
    The root folder of a JupyterLite project. env: JUPYTERLITE_DIR
    Default: traitlets.Undefined
    Equivalent to: [--LiteBuildConfig.lite_dir]
--contents=<typedtuple-item-1>...
    Contents to add and index
    Default: ()
    Equivalent to: [--LiteBuildConfig.contents]
--ignore-contents=<tuple-item-1>...
    Path regular expressions that should never be included as contents
    Default: ()
    Equivalent to: [--LiteBuildConfig.ignore_contents]
--extra-ignore-contents=<tuple-item-1>...
    Additional path regular expressions that should never be included as
    contents
    Default: ()
    Equivalent to: [--LiteBuildConfig.extra_ignore_contents]
--settings-overrides=<typedtuple-item-1>...
    Specific overrides.json to include
    Default: ()
    Equivalent to: [--LiteBuildConfig.settings_overrides]
--output-dir=<CPath>
    Where to build the JupyterLite site. env: JUPYTERLITE_OUTPUT_DIR
    Default: traitlets.Undefined
    Equivalent to: [--LiteBuildConfig.output_dir]
--output-archive=<CPath>
    Archive to create. env: JUPYTERLITE_OUTPUT_ARCHIVE
    Default: traitlets.Undefined
    Equivalent to: [--LiteBuildConfig.output_archive]
--source-date-epoch=<CInt>
    Trigger reproducible builds, clamping timestamps to this value
    Default: 0
    Equivalent to: [--LiteBuildConfig.source_date_epoch]
--port=<CInt>
    [serve] the port to (insecurely) expose on http://127.0.0.1. env:
    JUPYTERLITE_PORT
    Default: 0
    Equivalent to: [--LiteBuildConfig.port]
--base-url=<Unicode>
    [serve] the prefix to use. env: JUPYTERLITE_BASE_URL
    Default: ''
    Equivalent to: [--LiteBuildConfig.base_url]

To see all available configurables, use `--help-all`.

HTTP 标头#

在本地工作时,模拟与站点部署方式相匹配的 HTTP 标头会很方便。由于这些变得相当复杂,以下选项是可配置的,但只影响 jupyter lite serve,例如使用 extra_http_headers(扩展默认标头)或 http_headers(替换任何默认标头)模拟“宽松”主机

{
  "LiteBuildConfig": {
    "http_headers": {
      "Access-Control-Allow-Headers": "x-requested-with",
      "Access-Control-Allow-Methods": "POST, GET, OPTIONS",
      "Access-Control-Allow-Origin": "*"
    }
  }
}

检查#

使用所有可用机制验证构建文件夹是否符合架构等。

!jupyter lite check

隐藏代码单元格输出

static:jupyter-lite.json
.  pre_status:static:jupyter-lite.json
    tarball:         jupyterlite-app-0.6.4.tgz 15MB
    output:          /tmp/_my_lite_dir_monrxeo_/_output
    lite dir:        /tmp/_my_lite_dir_monrxeo_
    apps:            
    sourcemaps:      True
    unused packages: True
archive:archive
contents:contents
icons:icons
lite:jupyter-lite.json
mimetypes:jupyter-lite.json
serve:contents
settings:overrides
translation:translation
.  status:archive:archive
[LiteCheckApp] No archive (yet): _my_lite_dir_monrxeo_-jupyterlite.tgz
.  status:contents:contents
    contents: 0 files
.  status:icons:icons
    favicon files: 7 files
.  status:lite:jupyter-lite.json
[LiteCheckApp]     jupyter-lite.(json|ipynb): 0 files
.  status:mimetypes:jupyter-lite.json
    filetypes:         26 
.  status:serve:contents
    url: http://127.0.0.1:8000/
    server: tornado
    headers:
.  status:settings:overrides
    overrides.json: 0
.  status:translation:translation
    translation files: 4 files
static:output_dir
-- pre_init:static:output_dir
static:unpack
-- init:static:unpack
federated_extensions:copy:ext:jupyterlab_pygments
federated_extensions:copy:ext:@jupyter-notebook/lab-extension
-- pre_build:federated_extensions:copy:ext:jupyterlab_pygments
-- pre_build:federated_extensions:copy:ext:@jupyter-notebook/lab-extension
icons:copy
translation:copy
.  build:icons:copy
-- build:translation:copy
federated_extensions:patch
federated_extensions:settings
mimetypes:patch
.  post_build:federated_extensions:patch
-- post_build:federated_extensions:settings
-- post_build:mimetypes:patch
lite:validate:jupyter-lite.json
lite:validate:notebooks/jupyter-lite.json
lite:validate:repl/jupyter-lite.json
lite:validate:edit/jupyter-lite.json
lite:validate:tree/jupyter-lite.json
lite:validate:lab/jupyter-lite.json
lite:validate:consoles/jupyter-lite.json
lite:validate:jupyter-lite.ipynb
lite:validate:notebooks/jupyter-lite.ipynb
lite:validate:repl/jupyter-lite.ipynb
lite:validate:edit/jupyter-lite.ipynb
lite:validate:tree/jupyter-lite.ipynb
lite:validate:lab/jupyter-lite.ipynb
lite:validate:consoles/jupyter-lite.ipynb
translation:validate:translation:all.json
.  check:lite:validate:jupyter-lite.json
.  check:lite:validate:notebooks/jupyter-lite.json
.  check:lite:validate:repl/jupyter-lite.json
.  check:lite:validate:edit/jupyter-lite.json
.  check:lite:validate:tree/jupyter-lite.json
.  check:lite:validate:lab/jupyter-lite.json
.  check:lite:validate:consoles/jupyter-lite.json
.  check:lite:validate:jupyter-lite.ipynb
.  check:lite:validate:notebooks/jupyter-lite.ipynb
.  check:lite:validate:repl/jupyter-lite.ipynb
.  check:lite:validate:edit/jupyter-lite.ipynb
.  check:lite:validate:tree/jupyter-lite.ipynb
.  check:lite:validate:lab/jupyter-lite.ipynb
.  check:lite:validate:consoles/jupyter-lite.ipynb
.  check:translation:validate:translation:all.json

存档#

输出目录 转换为 .tgz 文件。这通常比(有时)数百个文件更容易移动,并且可以用作未来站点的基线。

此命令 相对 耗时,为文档目的跳过

!jupyter lite archive --help
if not RTD:
    !jupyter lite archive

隐藏代码单元格输出

A Jupyter Application

Options
=======
The options below are convenience aliases to configurable class-options,
as listed in the "Equivalent to" description-line of the aliases.
To see all configurable class-options for some <cmd>, use:
    <cmd> --help-all

--debug
    set log level to logging.DEBUG (maximize logging output)
    Equivalent to: [--Application.log_level=10]
-y
    Answer yes to any questions instead of prompting.
    Equivalent to: [--JupyterApp.answer_yes=True]
--ignore-sys-prefix
    Do not copy anything from sys.prefix
    Equivalent to: [--LiteBuildConfig.ignore_sys_prefix=True]
--no-sourcemaps
    Strip all sourcemaps from applications and extensions
    Equivalent to: [--LiteBuildConfig.no_sourcemaps=True]
--no-unused-shared-packages
    Remove shared packages not used by --apps
    Equivalent to: [--LiteBuildConfig.no_unused_shared_packages=True]
--no-libarchive
    Do not try to use libarchive-c for archive operations
    Equivalent to: [--LiteBuildConfig.no_libarchive=True]
--force
    forget previous runs of task and re-run from the beginning
    Equivalent to: [--LiteTaskApp.force=True]
--log-level=<Enum>
    Set the log level by value or name.
    Choices: any of [0, 10, 20, 30, 40, 50, 'DEBUG', 'INFO', 'WARN', 'ERROR', 'CRITICAL']
    Default: 30
    Equivalent to: [--Application.log_level]
--config=<Unicode>
    Full path of a config file.
    Default: ''
    Equivalent to: [--JupyterApp.config_file]
--disable-addons=<typedtuple-item-1>...
    skip loading `entry_point` for these addons. TODO: should be a dict
    Default: ()
    Equivalent to: [--LiteBuildConfig.disable_addons]
--app-archive=<CPath>
    The app archive to use. env: JUPYTERLITE_APP_ARCHIVE
    Default: traitlets.Undefined
    Equivalent to: [--LiteBuildConfig.app_archive]
--apps=<typedtuple-item-1>...
    the Lite apps to explicitly include in build e.g. lab, tree, repl
    Default: ()
    Equivalent to: [--LiteBuildConfig.apps]
--lite-dir=<CPath>
    The root folder of a JupyterLite project. env: JUPYTERLITE_DIR
    Default: traitlets.Undefined
    Equivalent to: [--LiteBuildConfig.lite_dir]
--contents=<typedtuple-item-1>...
    Contents to add and index
    Default: ()
    Equivalent to: [--LiteBuildConfig.contents]
--ignore-contents=<tuple-item-1>...
    Path regular expressions that should never be included as contents
    Default: ()
    Equivalent to: [--LiteBuildConfig.ignore_contents]
--extra-ignore-contents=<tuple-item-1>...
    Additional path regular expressions that should never be included as
    contents
    Default: ()
    Equivalent to: [--LiteBuildConfig.extra_ignore_contents]
--settings-overrides=<typedtuple-item-1>...
    Specific overrides.json to include
    Default: ()
    Equivalent to: [--LiteBuildConfig.settings_overrides]
--output-dir=<CPath>
    Where to build the JupyterLite site. env: JUPYTERLITE_OUTPUT_DIR
    Default: traitlets.Undefined
    Equivalent to: [--LiteBuildConfig.output_dir]
--output-archive=<CPath>
    Archive to create. env: JUPYTERLITE_OUTPUT_ARCHIVE
    Default: traitlets.Undefined
    Equivalent to: [--LiteBuildConfig.output_archive]
--source-date-epoch=<CInt>
    Trigger reproducible builds, clamping timestamps to this value
    Default: 0
    Equivalent to: [--LiteBuildConfig.source_date_epoch]
--port=<CInt>
    [serve] the port to (insecurely) expose on http://127.0.0.1. env:
    JUPYTERLITE_PORT
    Default: 0
    Equivalent to: [--LiteBuildConfig.port]
--base-url=<Unicode>
    [serve] the prefix to use. env: JUPYTERLITE_BASE_URL
    Default: ''
    Equivalent to: [--LiteBuildConfig.base_url]

To see all available configurables, use `--help-all`.

但是,让我们谈谈更 可重现 的资产。

隐藏代码单元格内容

# we clean out the TMP_DIR for the reproducibility examples
shutil.rmtree(TMP_DIR / "_output", ignore_errors=True)

可重现存档#

🛠️ 此功能正在 开发中,尚不应依赖于任何生产工作流。

如果给定 --source-date-epoch,将采取多项措施 尝试确保 jupyter lite archive 的输出(一个 npm 兼容的 tgz 包)始终返回位对位 可重现构建

最明显的变化是每个文件的修改时间“钳制”到该时间。其他一些变化是

  • 文件所有权将重置

  • 将使用可预测的排序

  • 将应用额外检查

注意

这是设置环境变量 SOURCE_DATE_EPOCH 的快捷方式

平台

命令

Linux
MacOS

export SOURCE_DATE_EPOCH=<a timestamp>

Windows

set SOURCE_DATE_EPOCH=<a timestamp>

Python

os.environ.update(SOURCE_DATE_EPOCH, <a timestamp>)

隐藏代码单元格源

if "source_date_epoch" not in globals():
    from datetime import datetime

    source_date_epoch = int(datetime.utcnow().timestamp())

print("SOURCE_DATE_EPOCH is", source_date_epoch)
SOURCE_DATE_EPOCH is 1754646237
/tmp/ipykernel_3501/711058523.py:4: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
  source_date_epoch = int(datetime.utcnow().timestamp())
if not RTD:
    !jupyter lite archive --source-date-epoch {source_date_epoch} --output-archive ./a.tgz

如果我们清除 _output...

隐藏代码单元格源

if not RTD:
    shutil.rmtree(TMP_DIR / "_output", ignore_errors=True)
    pprint.pprint([*TMP_DIR.rglob("*")])

...并重建,我们应该始终得到相同的文件。

if not RTD:
    !jupyter lite archive --source-date-epoch {source_date_epoch} --output-archive ./b.tgz

隐藏代码单元格源

if not RTD:
    a, b = (hashlib.sha256((TMP_DIR / f"{x}.tgz").read_bytes()).hexdigest() for x in "ab")
    print("We built app archives with the SHA256SUMS of:\n", a, "\n", b)
    try:
        assert a == b, f"We did not reproducibly build today.\n- {a}\n- {b}\n\n"
    except AssertionError:
        if shutil.which("diffoscope"):
            print("We did NOT reproducibly build today, checking in with `diffoscope`...")
            !diffoscope a.tgz b.tgz
        print("...but at least we tried REALLY hard!\n")

杂项#

合并内容#

除了默认的 files/ 路径之外,还可以使用 --contents 提供其他文件,以便在 JupyterLite 启动时显示在 文件管理器 中,该参数可以多次提供。

注意

  • 如果提供了 --contents,则 --contents files 的默认值将被忽略

  • 如果多次给定,并且子文件夹/文件名发生冲突,则 最后一个 路径获胜

提示

对于复杂的文件布局,强烈建议 使用 jupyter_lite_config.json

内容示例#

给定一个目录,例如

my-lite-dir/
  files/
    README.md
    a.md
  more-files/
    README.md
    b.md

不带任何参数运行 jupyter lite build 将产生

my-lite-dir/
  _output/
    README.md
    a.md

jupyter lite build --contents more-files --contents files 将产生

my-lite-dir/
  _output/
    files/
      README.md # this will be from my-lite-dir/files
      a.md
      b.md

jupyter lite build --contents files --contents more-files 将产生

my-lite-dir/
  _output/
    files/
      README.md # this will be from my-lite-dir/more-files
      a.md
      b.md

conda 包#

虽然 --federated-extensions 支持大多数 conda 包创建的 .tar.bz2,但存在一些问题

  • anaconda.org 使用非标准 HTTP 标头向 S3 存储桶提供包

  • conda-forge 频道将其所有构建作为 GitHub 发布提供,并且可以可预测地转换,例如

https://anaconda.org/conda-forge/jupyterlab_widgets/1.0.0/download/noarch/jupyterlab_widgets-1.0.0-pyhd8ed1ab_1.tar.bz2
                                                                   |      |
                                                                   |      +---------------------------------------------+
                                                                   v      v                                             v
         https://conda.anaconda.org/conda-forge/noarch/jupyterlab_widgets-1.0.0-pyhd8ed1ab_1.tar.bz2

Pyodide wheel 文件#

希望包含用于 Pyodide 内核 的 wheel 文件的 预构建 Lab 扩展 开发人员可以使用此命令预先索引他们希望分发的 wheel 文件。如果包需要上游补丁等,这会很有用。

!jupyter lite pip index --help

隐藏代码单元格输出

A Jupyter Application

Subcommands
===========
Subcommands are launched as `jupyter cmd [args]`. For information on using
subcommand 'cmd', do: `jupyter cmd -h`.

list
    describe a JupyterLite site
status
    report about what a JupyterLite build _might_ do
init
    initialize a JupyterLite site from an app archive baseline
build
    build a JupyterLite site, including user content
check
    verify a JupyterLite site, using available schema and rules
serve
    serve a JupyterLite site, using best available HTTP server
archive
    build a JupyterLite app archive, which can be used as a baseline
doit
    use the full doit CLI, see https://pydoit.org/contents.html

Options
=======
The options below are convenience aliases to configurable class-options,
as listed in the "Equivalent to" description-line of the aliases.
To see all configurable class-options for some <cmd>, use:
    <cmd> --help-all

--debug
    set log level to logging.DEBUG (maximize logging output)
    Equivalent to: [--Application.log_level=10]
-y
    Answer yes to any questions instead of prompting.
    Equivalent to: [--JupyterApp.answer_yes=True]
--ignore-sys-prefix
    Do not copy anything from sys.prefix
    Equivalent to: [--LiteBuildConfig.ignore_sys_prefix=True]
--no-sourcemaps
    Strip all sourcemaps from applications and extensions
    Equivalent to: [--LiteBuildConfig.no_sourcemaps=True]
--no-unused-shared-packages
    Remove shared packages not used by --apps
    Equivalent to: [--LiteBuildConfig.no_unused_shared_packages=True]
--no-libarchive
    Do not try to use libarchive-c for archive operations
    Equivalent to: [--LiteBuildConfig.no_libarchive=True]
--log-level=<Enum>
    Set the log level by value or name.
    Choices: any of [0, 10, 20, 30, 40, 50, 'DEBUG', 'INFO', 'WARN', 'ERROR', 'CRITICAL']
    Default: 30
    Equivalent to: [--Application.log_level]
--config=<Unicode>
    Full path of a config file.
    Default: ''
    Equivalent to: [--JupyterApp.config_file]
--disable-addons=<typedtuple-item-1>...
    skip loading `entry_point` for these addons. TODO: should be a dict
    Default: ()
    Equivalent to: [--LiteBuildConfig.disable_addons]
--app-archive=<CPath>
    The app archive to use. env: JUPYTERLITE_APP_ARCHIVE
    Default: traitlets.Undefined
    Equivalent to: [--LiteBuildConfig.app_archive]
--apps=<typedtuple-item-1>...
    the Lite apps to explicitly include in build e.g. lab, tree, repl
    Default: ()
    Equivalent to: [--LiteBuildConfig.apps]
--lite-dir=<CPath>
    The root folder of a JupyterLite project. env: JUPYTERLITE_DIR
    Default: traitlets.Undefined
    Equivalent to: [--LiteBuildConfig.lite_dir]
--contents=<typedtuple-item-1>...
    Contents to add and index
    Default: ()
    Equivalent to: [--LiteBuildConfig.contents]
--ignore-contents=<tuple-item-1>...
    Path regular expressions that should never be included as contents
    Default: ()
    Equivalent to: [--LiteBuildConfig.ignore_contents]
--extra-ignore-contents=<tuple-item-1>...
    Additional path regular expressions that should never be included as
    contents
    Default: ()
    Equivalent to: [--LiteBuildConfig.extra_ignore_contents]
--settings-overrides=<typedtuple-item-1>...
    Specific overrides.json to include
    Default: ()
    Equivalent to: [--LiteBuildConfig.settings_overrides]
--output-dir=<CPath>
    Where to build the JupyterLite site. env: JUPYTERLITE_OUTPUT_DIR
    Default: traitlets.Undefined
    Equivalent to: [--LiteBuildConfig.output_dir]
--output-archive=<CPath>
    Archive to create. env: JUPYTERLITE_OUTPUT_ARCHIVE
    Default: traitlets.Undefined
    Equivalent to: [--LiteBuildConfig.output_archive]
--source-date-epoch=<CInt>
    Trigger reproducible builds, clamping timestamps to this value
    Default: 0
    Equivalent to: [--LiteBuildConfig.source_date_epoch]
--port=<CInt>
    [serve] the port to (insecurely) expose on http://127.0.0.1. env:
    JUPYTERLITE_PORT
    Default: 0
    Equivalent to: [--LiteBuildConfig.port]
--base-url=<Unicode>
    [serve] the prefix to use. env: JUPYTERLITE_BASE_URL
    Default: ''
    Equivalent to: [--LiteBuildConfig.base_url]

To see all available configurables, use `--help-all`.

Pyodide#

Pyodide 是 CPython 的 WebAssembly 发行版,为 Pyodide 内核 提供支持。 Pyodide 完整发行版(压缩后近 200MB)包含 Python 解释器和科学计算堆栈中的关键锚包。默认情况下,用户浏览器会根据需要从官方 Pyodide CDN 获取其部分内容。

--pyodide CLI 选项(或 pyodide_url 配置选项或 JUPYTERLITE_PYODIDE_URL 环境变量)允许获取压缩的 Pyodide .bz2 文件,或包含此类存档内容的文件夹。这可能来自官方的 Pyodide 发布页面、每夜或 PR 资产,或经过定制的构建。获取后,它将被复制到输出文件夹并配置