9

I am having issue using Visual Studio Code. the code seem to have issue with ipywidgets. the code is below (very simple interactive chart)

from ipywidgets import interact
import ipywidgets as widgets
import numpy as np
import plotly.graph_objects as go
@interact
def foo(beta=(-10,10,1)):
    myx = np.arange(0,100,1)
    myy = myx *beta 
    print ('debug:',myy)
    fig = go.FigureWidget()
    fig.add_scatter(x= myx, y=myy)
    fig.show()

the same code works just as expected in Jupyter Notebook. I dig further and it seems:

"widgets require us to download supporting files from a 3rd party website. Error loading plotlywidget: ^4.14.3

https://github.com/microsoft/vscode-jupyter/wiki/IPyWidget-Support-in-VS-Code-Python

This is where I got stuck.. What's the next then to fix this issue?

any guidance much appreciated

thanks

cocojim
  • 223
  • 1
  • 2
  • 10

2 Answers2

13

Some of the issues I've seen reported seem to have started after the release of ipywidgets 8.

I don't understand exactly what's broken (or if it's broken), but downgrading to version 7.7.1 fixed all issues I was having.

If you want to try it as well, you can run: pip install -U ipywidgets==7.7.1

Lucas Farias
  • 418
  • 1
  • 8
  • 22
  • 2
    Great thanks this fixed my issues. Github issue here https://github.com/microsoft/vscode-jupyter/issues/8552 – sam Jan 30 '23 at 20:19
0

There two things you can explore.

  1. Check modules:

Run the jupyter --version command inside your conda or virtual environment. You should see something like this:

IPython          : 8.4.0
ipykernel        : 6.9.1
ipywidgets       : 7.7.1
jupyter_client   : 7.2.2
jupyter_core     : 4.10.0
jupyter_server   : 1.21.0
jupyterlab       : 3.4.8
nbclient         : 0.6.4
nbconvert        : 6.5.0
nbformat         : 5.4.0
notebook         : 6.4.12
qtconsole        : not installed
traitlets        : 5.4.0

If there are any of those modules not installed (Apart from qtconsole) try installing them (with pip install "module") and restarting the kernel.

  1. Check Jupyter nbextension.

As mentioned here after running pip install ipywidgets try:

jupyter nbextension enable --py widgetsnbextension

Note: If you are using virtual environments (including conda environments) the recommended way to activate the extension is to run

jupyter nbextension enable --py --sys-prefix widgetsnbextension

I hope this helps.