问题
In Jupyter Notebook, ipywidgets work fine, however they seem to not work in Jupyter Lab (which is supposedly better than Notebook).
I followed these directions.
Step 1: Installed Node.js (https://nodejs.org/en/)
Step 2: Installed requirements on Python 3 with conda:
conda install -c conda-forge ipywidgets
jupyter labextension install @jupyter-widgets/jupyterlab-manager
Unfortunately, basic widgets do not work inside the jupyter lab notebook:
回答1:
JupyterLab now prefers a model where 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 has an extension that can be activated by running this on your command line (which assumes you already have NodeJS installed):
jupyter labextension install @jupyter-widgets/jupyterlab-manager
回答2:
I had the same pbm, and tried this solution (hope it can help others):
The jupyter labextension install @jupyter-widgets/jupyterlab-manager
gave this kind of error in my case:
> /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
Then, what I did is to use a previous version 0.34 instead of 0.35:
jupyter labextension install @jupyter-widgets/jupyterlab-manager@0.34
In fact, according to this, sometime teams get time to consider the last version.
UP (according to comments):
You can check jupyter lab --version
and find match on its version compatibility.
And it works now !
回答3:
Had the same issue, and what worked for me today was running the 'clean' command, as mentioned here: https://ipywidgets.readthedocs.io/en/latest/user_install.html#installing-the-jupyterlab-extension
So:
jupyter lab clean
jupyter labextension install @jupyter-widgets/jupyterlab-manager
And that got it working right for me just now.
回答4:
I was getting a Permission Denied
error, so adding sudo
to the accepted command helped: sudo jupyter labextension install @jupyter-widgets/jupyterlab-manager
.
来源:https://stackoverflow.com/questions/49542417/how-to-get-ipywidgets-working-in-jupyter-lab