【问题标题】:Can't install any jupyterlab extensions in docker image无法在 docker 映像中安装任何 jupyterlab 扩展
【发布时间】:2026-01-11 15:30:01
【问题描述】:

我在本地主机上运行的管道代理上的 Azure 管道中运行 docker build 任务。我正在尝试“运行 jupyter labextension install @jupyter-widgets/jupyterlab-manager”。

在基础镜像中: node=14.14.0 jupyter=1.0.0 jupyter-packaging = 0.7.12 jupyter-resource-usage= 0.5.1 jupyter_client = 6.1.7 jupyter_console = 6.2.0 jupyter_core = 4.7.0 jupyter_server = 1.6.1 jupyter_telemetry = 0.1.0 jupyterhub = 1.3.0 jupyterhub-base = 1.3.0 jupyterlab = 3.0.12 jupyterlab-git = 0.30.0b2 jupyterlab-templates = 0.2.5 jupyterlab_code_formatter=1.4.5 jupyterlab_pygments = 0.1.2 jupyterlab_server = 2.3.0

Dockerfile 看起来像这样:

USER root
COPY files/.npmrc $HOME/.npmrc
RUN jupyter labextension install --no-build @jupyter-widgets/jupyterlab-manager .....

.npmrc 看起来像这样:

always-auth=true
strict-ssl=false
registry=https://pkgs.dev.azure.com/org-name/proj-name/_packaging/proj-name/npm/registry/
https-proxy=the-proxy-url
proxy=the-proxy-url

管道执行以下任务:

  1. 在 .npmrc 上运行 npmAuthenticate 任务以使用 auth-token 编辑 .npmrc 文件。这成功了..
  2. 接下来运行 docker build。 Dockerfile 指示将此修改后的 .npmrc 复制到 $HOME 并尝试安装实验室扩展

找到这个帖子:https://github.com/jupyter-widgets/ipywidgets/issues/1982#issuecomment-468716770 我们使用 jupyterlab v3。所以 node>=12 是必需的。所以我把 Dockerfile 改成:

USER root
COPY files/.npmrc $HOME/.npmrc
RUN conda remove nodejs && conda install -c conda-forge nodejs=12 && conda list | grep nodejs &&\
jupyter labextension install --no-build @jupyter-widgets/jupyterlab-manager .....

也试过这个:https://*.com/a/52484330/3575135。没有帮助

正常的“npm install @angular/cli”可以正常工作。但是实验室的扩展让我很难过。在这一点上似乎没有任何工作..

这是错误:

ValueError: "@jupyter-widgets/jupyterlab-manager" is not a valid npm package

请帮忙!

【问题讨论】:

  • 错误提示包不在此注册表中-> https://pkgs.dev.azure.com/org-name/proj-name/_packaging/proj-name/npm/registry/ 你把包放在那里了吗?我假设它是您的私人注册表。
  • 这个包在公共的 npmjs 注册表中。注册表已将 npmjs 设置为上游源
  • 您是否已经尝试将这个注册表 commet 出来以尝试直接从官方 npm 获取?您可以在本地按照您想要在 docker 中执行的步骤进行操作吗?具体来说,这是您可以在任何地方成功执行的有效评论吗? jupyter labextension install --no-build @jupyter-widgets/jupyterlab-manager
  • 我查看了这个 (github.com/postmanlabs/npm-cli-login/issues/…) 并将 npmrc 复制到 /.npmrc 而不是 $HOME/.npmrc。它似乎奏效了。构建将需要另外 2-4 小时才能完成。如果一切正常,将测试图像并关闭问题! :) 谢谢!
  • 当然,您将 root 用户放在 docker 文件的顶部。奇怪的是,您现在的文件位于 /.npmrc 而不是 /root/.npmrc,因为从技术上讲,这是根主文件夹。啊等等,但是 $HOME 应该也可以工作。嗯。

标签: python node.js docker npm jupyter-lab


【解决方案1】:

您不应该为 JupyterLab 3.0+ 安装 Node.js 或 @jupyter-widgets/jupyterlab-manager。扩展系统得到了改进,新的“联合扩展”系统不再需要 Node.js(并且大多数扩展已经从 Node.js 的要求中迁移出来)。 @jupyter-widgets/jupyterlab-manager 的自述文件明确指出,对于 JupyterLab 3.0+,您应该使用:

pip install jupyterlab_widgets

大多数扩展也是如此 - 如果它们迁移,它们将在其自述文件中包含 PyPI 包的名称。更深入的解释请阅读this answer

作为一个好的建议,请仅将 jupyter labextension install 用于尚未迁移到 pip/conda 可安装联合扩展的扩展。

【讨论】:

    【解决方案2】:

    将 npmrc 复制到 /.npmrc 而不是 $HOME/.npmrc。这有效

    【讨论】: