如何让 ipywidgets 在 Jupyter Lab 中工作?
How to get ipywidgets working in Jupyter Lab?
在 Jupyter Notebook 中,ipywidgets 工作正常,但它们似乎在 Jupyter Lab 中不起作用(据说比 Notebook 更好)。
我关注了这些directions。
第 1 步: 已安装 Node.js (https://nodejs.org/en/)
步骤 2: 使用 conda 在 Python 3 上安装要求:
conda install -c conda-forge ipywidgets
jupyter labextension install @jupyter-widgets/jupyterlab-manager
遗憾的是,基本小部件在 jupyter 实验室笔记本中不起作用:
JupyterLab 现在更喜欢 arbitrary javascript is no longer allowed to be embedded in a cell's output, which is how many interactive Jupyter Notebook modules used to work. They now ask that modules with interactivity create a JupyterLab extension 的模型。
ipywidgets 提供了满足此要求的 @jupyter-widgets/jupyterlab-manager
扩展。
在 JupyterLab 3.0 或更新版本中使用 ipywidgets 7.6 或更新版本时,您无需执行任何操作:它是 installed by default。您可以通过 运行:
检查是否已安装
jupyter labextension list
其中应该包括一行:
@jupyter-widgets/jupyterlab-manager v3.0.0 enabled OK (python, jupyterlab_widgets)
如果您使用的是 JupyterLab 1 或 2(或旧版本的 ipywidgets),则需要安装此扩展 manually by running this on your command line (which assumes you already have NodeJS 安装:
jupyter labextension install @jupyter-widgets/jupyterlab-manager
我有相同的 pbm,并尝试了这个解决方案(希望它可以帮助其他人):
jupyter labextension install @jupyter-widgets/jupyterlab-manager
在我的案例中给出了这种错误:
> /Users/user/.nvm/versions/node/v8.7.0/bin/npm pack @jupyter-widgets/jupyterlab-manager
jupyter-widgets-jupyterlab-manager-0.35.0.tgz
Errored, use --debug for full output:
ValueError:
"@jupyter-widgets/jupyterlab-manager@0.35.0" is not compatible with the current JupyterLab
Conflicting Dependencies:
JupyterLab Extension Package
>=0.15.4-0 <0.16.0-0 >=0.16.0-0 <0.17.0-0 @jupyterlab/application
>=1.1.4-0 <2.0.0-0 >=2.0.0-0 <3.0.0-0 @jupyterlab/services
>=0.15.4-0 <0.16.0-0 >=0.16.0-0 <0.17.0-0 @jupyterlab/rendermime
>=0.15.4-0 <0.16.0-0 >=0.16.0-0 <0.17.0-0 @jupyterlab/notebook
然后,我做的是使用以前的版本 0.34 而不是 0.35:
jupyter labextension install @jupyter-widgets/jupyterlab-manager@0.34
事实上,根据 this,有时团队会有时间考虑最后一个版本。
UP(根据评论):
您可以检查 jupyter lab --version
并在 its version compatibility 上找到匹配项。
现在可以使用了!
有同样的问题,今天对我有用的是 运行 'clean' 命令,如下所述:https://ipywidgets.readthedocs.io/en/latest/user_install.html#installing-the-jupyterlab-extension
所以:
jupyter lab clean
jupyter labextension install @jupyter-widgets/jupyterlab-manager
这让它现在对我有用。
我遇到了 Permission Denied
错误,因此将 sudo
添加到已接受的命令中有帮助:sudo jupyter labextension install @jupyter-widgets/jupyterlab-manager
.
None 的其他答案对我有用。这一切似乎都取决于版本兼容性。终于让它工作了 - 见下文。
所有功劳都归功于@hainm github(原文link:https://github.com/jupyter-widgets/ipywidgets/issues/2488#issuecomment-509719214)
我对此的回答是:
这是该答案的直接副本:
利用 https://github.com/jupyter-widgets/ipywidgets/issues/2488#issuecomment-509719214,在 jupyterlab 终端中 - 运行 在 jupyterhub 上 - 执行:
pythonversion=3.7
labversion=0.34.12
labmanagerversion=0.37.4
ipywidgetsversion=7.4.2
conda install ipywidgets=$ipywidgetsversion -c conda-forge -y --override-channels -c main
conda install jupyterlab=$labversion -y -c conda-forge --override-channels -c main
jupyter-labextension install @jupyter-widgets/jupyterlab-manager@$labmanagerversion
此时 jupyter lab clean; jupyter lab build
可能会感兴趣。
然后在同一个 jupyterlab window 的 .ipynb notebook 运行 中,点击重启内核按钮。
重要提示:别忘了REFRESH浏览器页面 - 否则所有努力都将白费。 :\
然后执行例子:
from ipywidgets import interact
@interact(x=(0, 100, 10))
def p(x=50):
pass
我从没想过我能活到这一天,但是 - 嘿,转眼间 - 小部件终于出现了!
可悲的是,设置对其他扩展的安装极其敏感,兼容版本的组合非常具体。
根据 ipywidgets.readthedocs.io documentation (Installing the JupyterLab Extension),对于“JupyterLab”,请在“Anaconda Prompt”中执行以下步骤。
步骤 1
conda install -c conda-forge nodejs
步骤 2
jupyter labextension install @jupyter-widgets/jupyterlab-manager
如果你在 linux 和 你宁愿完全避免 conda,并使用虚拟环境 (venvs) 来保持 python 快乐,并且您碰巧正在使用基于 'older'/LTS Debian 的 OS,它可能没有最新的 nodejs:即 Ubuntu 16.04 LTS,它没有 node
而是 nodejs
(node
属于另一个包,'legacy nodejs' 版本太旧),然后继续阅读。
这个 设置起来有点复杂,但比 conda 更容易长期维护。 (你总是可以为新项目创建一个新的 venv
,而不会破坏你的旧项目)。
要点是:
- 使用 PPA 获取所需内容的最新版本
- 使用 virtualenvwrapper 这样你就可以:
- 使用最新的python3
- 避免弄乱你的'pip install'的
- 避免混淆系统包管理器
- 也可以轻松地与使用不同版本 python
的人一起工作
- 遵循python最佳实践
- 很容易有不同的 venvs,它们可能有旧的或不兼容的 python 和 pip 包。
- 使用Nodejs binary distributions
- jupyterlab 小部件需要 node.js 版本“10.x”
- 允许使用系统的包管理器来保持 nodejs 的新鲜
- 只要 LTS 是
,就会得到维护和可用
因此,所有实际步骤(这些都经过测试可在 Linux Mint 18.3 Sylvia 上运行,它基本上与 ubuntu xenial aka Ubuntu 16.04 LTS 兼容。主要会出现差异在nodejs中,阅读上面github link中的readme来解决其他OS):
让管理员来做(如果可以的话,自己做 sudo):
sudo apt update
sudo apt install software-properties-common
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update
sudo apt install -y python3.8 python3.8-dev python3.8-distutils python3-pip python3-venv
curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
sudo apt-get install -y nodejs
然后,作为您自己的用户,您可以完成剩余的步骤:
pip3 install --user virtualenv virtualenvwrapper
mkdir ~/.envs
然后您需要将以下内容添加到 .bashrc
的末尾:
export PATH=~/.local/bin:$PATH
export WORKON_HOME=~/.envs
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
source ~/.local/bin/virtualenvwrapper.sh
此时,制作一个新的 shell,您将能够 运行 其余的设置,实际安装 jupyterlab:
mkvirtualenv -p python3.8 jupenv
pip install jupyter matplotlib pandas ipympl tqdm
jupyter labextension install @jupyter-widgets/jupyterlab-manager
大功告成。
到 open/use jupyter,你想要(因为我在上面调用了 jupenv
的 venv,你可以在 mkvirtualenv
行中随意命名它):
workon jupenv
jupyter lab
否则,我没完没了地试图让 nodejs 与过时的 ubuntu 包一起工作。有时它会工作,重新启动几次,然后失败。其他时候,它只会不断给我同样丢失的小部件,或者有时是几行垃圾 js 代码。
Virtualenvs 非常值得使用,尤其是当您开始认真使用 python 并与可能使用不同版本/不同 pip 包集的其他人一起工作时。 VirtualEnvWrapper 使这非常轻松。
基本点是,你 'pip install',甚至是 jupyter,最终都被干净地分开(并且与系统包分开),这使一切都很好地工作。
有一些基本的注意事项:
- 不要 运行
pip install ...
行而不在 venv
- 不要在 venv 中使用
pip3
代替 pip
。
- 请在 运行 中使用
python
而不是 python3
。
- 不要使用
conda...
!
- 请知道您可以通过以下方式立即更新所有 virtualenvs:
allvirtualenv pip install -U pip
至于 nodejs 二进制分发包:强烈推荐它们支持您的特定 OS。它们将是最新的并且应该出现最少的麻烦。
我和@jtlz2 有同样的问题,上面建议的 none 对我有用,除了 @hainm 的 jupyter-lab、ipywidgests 和 jupyter-widgets/jupyterlab-manager 的非常具体的版本组合。
根据此 post (https://github.com/jupyter-widgets/ipywidgets/issues/2488#issuecomment-509719214) 中列出的初始版本号,我试图找到最新的可用版本组合。我在下面列出了它们,这样如果 him/her.
确实没有其他工作,人们可以尝试一下
pythonversion=3.8.0
labversion=2.1.5
labmanagerversion=2.0
ipywidgetsversion=7.5.1
nodejsversion=10.13.0
conda create -n lab python=$pythonversion -y
source activate lab
conda install nodejs=$nodejsversion -c conda-forge -y
conda install ipywidgets=$ipywidgetsversion -c conda-forge -y
conda install jupyterlab=$labversion -y -c conda-forge
jupyter-labextension install @jupyter-widgets/jupyterlab-manager@$labmanagerversion
看来nodejs的版本起了关键作用。保持其他一切相同,如果我将 nodejsversion 更新为 12.x+ 或最新的 14.x,此组合以及@hainm 的组合都无法使 ipywidgets 在 Jupyterlab 中正常运行。
除了我在上面的代码单元格中列出的组合之外,以下 6 种组合也适用于我。
(python版本,lab版本,labmanager版本,ipywidgets,nodejs版本)
- (3.7, 0.34, 0.37, 7.4.2, 10.13)
- (3.7, 1.0, 1.0, 7.4.2, 10.13)
- (3.7, 2.0, 2.0, 7.4.2, 10.13)
- (3.8, 2.0, 2.0, 7.4.2, 10.13)
- (3.8, 2.0, 2.0, 7.5.1, 10.13)
- (3.8, 2.1.5, 2.0, 7.5.1, 10.13)
注意:以上大部分答案已过时(截至 2021 年 7 月 19 日)。这些软件包的最新版本应该更加无缝。但是,在 2021 年,我在 jupyterhub 上托管的 jupyterlab 中呈现 panel
小部件时遇到了问题,并遇到了这个 post。起初我尝试了其中的一些答案,但其中 none 有效。在深入研究了一些库之后,我发现了以下内容:
从 ipywidgets==7.6
和 jupyterlab>=3.0
开始,不再需要 jupyter labextension install @jupyter-widgets/jupyterlab-manager
。 source. If you're on the latest version of jupyterlab, you should just need to install ipywidgets
and the extension will be enabled automatically as long as widget extension authors also follow some steps。
The main change in this release is that installing ipywidgets 7.6.0 will now automatically enable ipywidgets support in JupyterLab 3.0—a user has no extra JupyterLab installation step and no rebuild of JupyterLab, nor do they need Node.js installed. Simply install the python ipywidgets package with pip (pip install ipywidgets==7.6.0) or conda/mamba (conda install -c conda-forge ipywidgets=7.6.0) and ipywidgets will automatically work in classic Jupyter Notebook and in JupyterLab 3.0.
panel
也效仿并将必要的扩展捆绑在 pyviz_comms
包中,因此理论上我的案例应该包含所有内容。 source
In the classic Jupyter notebook environment and JupyterLab, first make sure to load the pn.extension(). Panel objects will then render themselves if they are the last item in a notebook cell. For versions of jupyterlab>=3.0 the necessary extension is automatically bundled in the pyviz_comms package, which must be >=2.0.
我的问题的答案原来是我在通过 jupyterhub 构建 jupyterlab 服务器后 panel
安装。 (例如,对于特定笔记本,用户是 运行 !pip install panel
)。这是我有点模糊的地方,因为我不确定为什么这不起作用,因为 ipywidgets
已经安装并且 panel
安装包括预构建的 jupyterlab 扩展。但是,我能够通过使用 jupyterlab 图像从预安装了 ipywidgets>=7.6
和 panel>=0.11.3
(因此 pyviz_comms>=2.0
)的 jupyterhub 生成来解决我的问题。在此之后,jupyterhub 上的 jupyterlab 中的面板小部件现在可以工作了。希望这对遇到类似问题的人有所帮助。
请检查在 Jupyter 3.0 中运行的步骤docs
请检查使其在 Jupyter 1 0r 2 中运行的步骤 docs
在此之后重新启动或构建实验室以查看更改
除此之外,确保您的 ipywidgets 安装在与 jupyterlab 相同的 conda 环境中。
这是我的故事(通过 conda inside docker 安装的 ipywidgets 7.7.0、jupyterlab 3.2.5):
- 运行 docker在基础 conda 环境中
jupyterlab
化
- 创建了新的 conda 环境,安装
ipykernel
,使其对 jupyterlab
可见,安装 ipywidgets
- 切换到新内核,现在
jupyterlab
识别 ipywidgets
已安装,但小部件不工作(仅显示文本小部件描述),这令人困惑
解决方案:
- 在与jupyterlab相同的conda环境下安装ipywidgets
免责声明:我的回答可能不适用于原问题,因为作者没有使用单独的conda环境。但它可能对其他面临类似问题的人有用。
在 Jupyter Notebook 中,ipywidgets 工作正常,但它们似乎在 Jupyter Lab 中不起作用(据说比 Notebook 更好)。
我关注了这些directions。
第 1 步: 已安装 Node.js (https://nodejs.org/en/)
步骤 2: 使用 conda 在 Python 3 上安装要求:
conda install -c conda-forge ipywidgets
jupyter labextension install @jupyter-widgets/jupyterlab-manager
遗憾的是,基本小部件在 jupyter 实验室笔记本中不起作用:
JupyterLab 现在更喜欢 arbitrary javascript is no longer allowed to be embedded in a cell's output, which is how many interactive Jupyter Notebook modules used to work. They now ask that modules with interactivity create a JupyterLab extension 的模型。
ipywidgets 提供了满足此要求的 @jupyter-widgets/jupyterlab-manager
扩展。
在 JupyterLab 3.0 或更新版本中使用 ipywidgets 7.6 或更新版本时,您无需执行任何操作:它是 installed by default。您可以通过 运行:
检查是否已安装jupyter labextension list
其中应该包括一行:
@jupyter-widgets/jupyterlab-manager v3.0.0 enabled OK (python, jupyterlab_widgets)
如果您使用的是 JupyterLab 1 或 2(或旧版本的 ipywidgets),则需要安装此扩展 manually by running this on your command line (which assumes you already have NodeJS 安装:
jupyter labextension install @jupyter-widgets/jupyterlab-manager
我有相同的 pbm,并尝试了这个解决方案(希望它可以帮助其他人):
jupyter labextension install @jupyter-widgets/jupyterlab-manager
在我的案例中给出了这种错误:
> /Users/user/.nvm/versions/node/v8.7.0/bin/npm pack @jupyter-widgets/jupyterlab-manager
jupyter-widgets-jupyterlab-manager-0.35.0.tgz
Errored, use --debug for full output:
ValueError:
"@jupyter-widgets/jupyterlab-manager@0.35.0" is not compatible with the current JupyterLab
Conflicting Dependencies:
JupyterLab Extension Package
>=0.15.4-0 <0.16.0-0 >=0.16.0-0 <0.17.0-0 @jupyterlab/application
>=1.1.4-0 <2.0.0-0 >=2.0.0-0 <3.0.0-0 @jupyterlab/services
>=0.15.4-0 <0.16.0-0 >=0.16.0-0 <0.17.0-0 @jupyterlab/rendermime
>=0.15.4-0 <0.16.0-0 >=0.16.0-0 <0.17.0-0 @jupyterlab/notebook
然后,我做的是使用以前的版本 0.34 而不是 0.35:
jupyter labextension install @jupyter-widgets/jupyterlab-manager@0.34
事实上,根据 this,有时团队会有时间考虑最后一个版本。
UP(根据评论):
您可以检查 jupyter lab --version
并在 its version compatibility 上找到匹配项。
现在可以使用了!
有同样的问题,今天对我有用的是 运行 'clean' 命令,如下所述:https://ipywidgets.readthedocs.io/en/latest/user_install.html#installing-the-jupyterlab-extension
所以:
jupyter lab clean
jupyter labextension install @jupyter-widgets/jupyterlab-manager
这让它现在对我有用。
我遇到了 Permission Denied
错误,因此将 sudo
添加到已接受的命令中有帮助:sudo jupyter labextension install @jupyter-widgets/jupyterlab-manager
.
None 的其他答案对我有用。这一切似乎都取决于版本兼容性。终于让它工作了 - 见下文。
所有功劳都归功于@hainm github(原文link:https://github.com/jupyter-widgets/ipywidgets/issues/2488#issuecomment-509719214)
我对此的回答是:
利用 https://github.com/jupyter-widgets/ipywidgets/issues/2488#issuecomment-509719214,在 jupyterlab 终端中 - 运行 在 jupyterhub 上 - 执行:
pythonversion=3.7
labversion=0.34.12
labmanagerversion=0.37.4
ipywidgetsversion=7.4.2
conda install ipywidgets=$ipywidgetsversion -c conda-forge -y --override-channels -c main
conda install jupyterlab=$labversion -y -c conda-forge --override-channels -c main
jupyter-labextension install @jupyter-widgets/jupyterlab-manager@$labmanagerversion
此时 jupyter lab clean; jupyter lab build
可能会感兴趣。
然后在同一个 jupyterlab window 的 .ipynb notebook 运行 中,点击重启内核按钮。
重要提示:别忘了REFRESH浏览器页面 - 否则所有努力都将白费。 :\
然后执行例子:
from ipywidgets import interact
@interact(x=(0, 100, 10))
def p(x=50):
pass
我从没想过我能活到这一天,但是 - 嘿,转眼间 - 小部件终于出现了!
可悲的是,设置对其他扩展的安装极其敏感,兼容版本的组合非常具体。
根据 ipywidgets.readthedocs.io documentation (Installing the JupyterLab Extension),对于“JupyterLab”,请在“Anaconda Prompt”中执行以下步骤。
步骤 1
conda install -c conda-forge nodejs
步骤 2
jupyter labextension install @jupyter-widgets/jupyterlab-manager
如果你在 linux 和 你宁愿完全避免 conda,并使用虚拟环境 (venvs) 来保持 python 快乐,并且您碰巧正在使用基于 'older'/LTS Debian 的 OS,它可能没有最新的 nodejs:即 Ubuntu 16.04 LTS,它没有 node
而是 nodejs
(node
属于另一个包,'legacy nodejs' 版本太旧),然后继续阅读。
这个 设置起来有点复杂,但比 conda 更容易长期维护。 (你总是可以为新项目创建一个新的 venv
,而不会破坏你的旧项目)。
要点是:
- 使用 PPA 获取所需内容的最新版本
- 使用 virtualenvwrapper 这样你就可以:
- 使用最新的python3
- 避免弄乱你的'pip install'的
- 避免混淆系统包管理器
- 也可以轻松地与使用不同版本 python 的人一起工作
- 遵循python最佳实践
- 很容易有不同的 venvs,它们可能有旧的或不兼容的 python 和 pip 包。
- 使用Nodejs binary distributions
- jupyterlab 小部件需要 node.js 版本“10.x”
- 允许使用系统的包管理器来保持 nodejs 的新鲜
- 只要 LTS 是 ,就会得到维护和可用
因此,所有实际步骤(这些都经过测试可在 Linux Mint 18.3 Sylvia 上运行,它基本上与 ubuntu xenial aka Ubuntu 16.04 LTS 兼容。主要会出现差异在nodejs中,阅读上面github link中的readme来解决其他OS):
让管理员来做(如果可以的话,自己做 sudo):
sudo apt update
sudo apt install software-properties-common
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update
sudo apt install -y python3.8 python3.8-dev python3.8-distutils python3-pip python3-venv
curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
sudo apt-get install -y nodejs
然后,作为您自己的用户,您可以完成剩余的步骤:
pip3 install --user virtualenv virtualenvwrapper
mkdir ~/.envs
然后您需要将以下内容添加到 .bashrc
的末尾:
export PATH=~/.local/bin:$PATH
export WORKON_HOME=~/.envs
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
source ~/.local/bin/virtualenvwrapper.sh
此时,制作一个新的 shell,您将能够 运行 其余的设置,实际安装 jupyterlab:
mkvirtualenv -p python3.8 jupenv
pip install jupyter matplotlib pandas ipympl tqdm
jupyter labextension install @jupyter-widgets/jupyterlab-manager
大功告成。
到 open/use jupyter,你想要(因为我在上面调用了 jupenv
的 venv,你可以在 mkvirtualenv
行中随意命名它):
workon jupenv
jupyter lab
否则,我没完没了地试图让 nodejs 与过时的 ubuntu 包一起工作。有时它会工作,重新启动几次,然后失败。其他时候,它只会不断给我同样丢失的小部件,或者有时是几行垃圾 js 代码。
Virtualenvs 非常值得使用,尤其是当您开始认真使用 python 并与可能使用不同版本/不同 pip 包集的其他人一起工作时。 VirtualEnvWrapper 使这非常轻松。 基本点是,你 'pip install',甚至是 jupyter,最终都被干净地分开(并且与系统包分开),这使一切都很好地工作。
有一些基本的注意事项:
- 不要 运行
pip install ...
行而不在 venv - 不要在 venv 中使用
pip3
代替pip
。 - 请在 运行 中使用
python
而不是python3
。 - 不要使用
conda...
! - 请知道您可以通过以下方式立即更新所有 virtualenvs:
allvirtualenv pip install -U pip
至于 nodejs 二进制分发包:强烈推荐它们支持您的特定 OS。它们将是最新的并且应该出现最少的麻烦。
我和@jtlz2 有同样的问题,上面建议的 none 对我有用,除了 @hainm 的 jupyter-lab、ipywidgests 和 jupyter-widgets/jupyterlab-manager 的非常具体的版本组合。
根据此 post (https://github.com/jupyter-widgets/ipywidgets/issues/2488#issuecomment-509719214) 中列出的初始版本号,我试图找到最新的可用版本组合。我在下面列出了它们,这样如果 him/her.
确实没有其他工作,人们可以尝试一下pythonversion=3.8.0
labversion=2.1.5
labmanagerversion=2.0
ipywidgetsversion=7.5.1
nodejsversion=10.13.0
conda create -n lab python=$pythonversion -y
source activate lab
conda install nodejs=$nodejsversion -c conda-forge -y
conda install ipywidgets=$ipywidgetsversion -c conda-forge -y
conda install jupyterlab=$labversion -y -c conda-forge
jupyter-labextension install @jupyter-widgets/jupyterlab-manager@$labmanagerversion
看来nodejs的版本起了关键作用。保持其他一切相同,如果我将 nodejsversion 更新为 12.x+ 或最新的 14.x,此组合以及@hainm 的组合都无法使 ipywidgets 在 Jupyterlab 中正常运行。
除了我在上面的代码单元格中列出的组合之外,以下 6 种组合也适用于我。
(python版本,lab版本,labmanager版本,ipywidgets,nodejs版本)
- (3.7, 0.34, 0.37, 7.4.2, 10.13)
- (3.7, 1.0, 1.0, 7.4.2, 10.13)
- (3.7, 2.0, 2.0, 7.4.2, 10.13)
- (3.8, 2.0, 2.0, 7.4.2, 10.13)
- (3.8, 2.0, 2.0, 7.5.1, 10.13)
- (3.8, 2.1.5, 2.0, 7.5.1, 10.13)
注意:以上大部分答案已过时(截至 2021 年 7 月 19 日)。这些软件包的最新版本应该更加无缝。但是,在 2021 年,我在 jupyterhub 上托管的 jupyterlab 中呈现 panel
小部件时遇到了问题,并遇到了这个 post。起初我尝试了其中的一些答案,但其中 none 有效。在深入研究了一些库之后,我发现了以下内容:
-
从
jupyter labextension install @jupyter-widgets/jupyterlab-manager
。 source. If you're on the latest version of jupyterlab, you should just need to installipywidgets
and the extension will be enabled automatically as long as widget extension authors also follow some steps。The main change in this release is that installing ipywidgets 7.6.0 will now automatically enable ipywidgets support in JupyterLab 3.0—a user has no extra JupyterLab installation step and no rebuild of JupyterLab, nor do they need Node.js installed. Simply install the python ipywidgets package with pip (pip install ipywidgets==7.6.0) or conda/mamba (conda install -c conda-forge ipywidgets=7.6.0) and ipywidgets will automatically work in classic Jupyter Notebook and in JupyterLab 3.0.
panel
也效仿并将必要的扩展捆绑在pyviz_comms
包中,因此理论上我的案例应该包含所有内容。 sourceIn the classic Jupyter notebook environment and JupyterLab, first make sure to load the pn.extension(). Panel objects will then render themselves if they are the last item in a notebook cell. For versions of jupyterlab>=3.0 the necessary extension is automatically bundled in the pyviz_comms package, which must be >=2.0.
ipywidgets==7.6
和 jupyterlab>=3.0
开始,不再需要 我的问题的答案原来是我在通过 jupyterhub 构建 jupyterlab 服务器后 panel
安装。 (例如,对于特定笔记本,用户是 运行 !pip install panel
)。这是我有点模糊的地方,因为我不确定为什么这不起作用,因为 ipywidgets
已经安装并且 panel
安装包括预构建的 jupyterlab 扩展。但是,我能够通过使用 jupyterlab 图像从预安装了 ipywidgets>=7.6
和 panel>=0.11.3
(因此 pyviz_comms>=2.0
)的 jupyterhub 生成来解决我的问题。在此之后,jupyterhub 上的 jupyterlab 中的面板小部件现在可以工作了。希望这对遇到类似问题的人有所帮助。
请检查在 Jupyter 3.0 中运行的步骤docs
请检查使其在 Jupyter 1 0r 2 中运行的步骤 docs
在此之后重新启动或构建实验室以查看更改
除此之外,确保您的 ipywidgets 安装在与 jupyterlab 相同的 conda 环境中。
这是我的故事(通过 conda inside docker 安装的 ipywidgets 7.7.0、jupyterlab 3.2.5):
- 运行 docker在基础 conda 环境中
jupyterlab
化 - 创建了新的 conda 环境,安装
ipykernel
,使其对jupyterlab
可见,安装ipywidgets
- 切换到新内核,现在
jupyterlab
识别ipywidgets
已安装,但小部件不工作(仅显示文本小部件描述),这令人困惑
解决方案:
- 在与jupyterlab相同的conda环境下安装ipywidgets
免责声明:我的回答可能不适用于原问题,因为作者没有使用单独的conda环境。但它可能对其他面临类似问题的人有用。