How to get ipywidgets working in Jupyter Lab?

后端 未结 8 1123
北海茫月
北海茫月 2020-12-07 17:39

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.

8条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-07 18:06

    None of the other answers worked to me. It all seems to be down to version compatibility. Finally got it working - see below. All credit to @hainm on github (original link: https://github.com/jupyter-widgets/ipywidgets/issues/2488#issuecomment-509719214) My SO answer on this: https://stackoverflow.com/a/60059786/1021819 Here is a straight copy of that answer:

    Leveraging https://github.com/jupyter-widgets/ipywidgets/issues/2488#issuecomment-509719214, in a jupyterlab terminal - running on jupyterhub - execute:

    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
    

    At this point a jupyter lab clean; jupyter lab build might be of interest.

    Then in a .ipynb notebook running in the same jupyterlab window, hit the restart kernel button.

    IMPORTANT: Don't forget to also REFRESH the browser page - or all efforts will have been in vain . :\

    Then execute the example:

    from ipywidgets import interact
    
    @interact(x=(0, 100, 10))
    def p(x=50):
        pass
    

    I never thought I would live to see the day but - hey presto - the widget finally appears!

    The sad things are that the setup is extremely sensitive to the installation of other extensions and the combination of compatible versions is very specific.

提交回复
热议问题