ipywidgets
ipywidgets copied to clipboard
Error displaying widget and several Javascript errors
Description
I am trying to visualize a .vtk file with itkwidgets in Jupyterlab with this code:
import pyvista as pv
data = pv.read('~/Desktop/samo/prvivtk.vtk')
from itkwidgets import view
view(geometries=data)
the file in question: prvivtk.zip
When doing so I get the following Javascript error in the browser console:

After looking through the code I found the JS errors come from the module ipywidgets, which is why I am addressing the issue here. As a test I tried to then run a simple ipywidgets example of a slider, which can be found below in the reproduce section. The example did not work either and resulted in the same error: Error displaying widget, as well as the same browser console output.
All of the modules and outputs are run in a virtual environment with Python 3.9.14.
I noticed some other people reporting similar issues regarding the errors with displaying widgets but none of the answers quite cleared up the issues for me.
Expected behavior
The following output was produced without any other changes than using Jupyter Notebook instead of JupyterLab:

Reproduce
Step-by-step instructions
Install jupyterlab: pip install jupyterlab
Create a virtual environment. I did it using this code:
# Create a new venv virtual environment with Python 3.9 in it
me@mydevice:~$ python3.9 -m venv ~/.venvs/my-venv-name
Install the following in venv:
pip install itkwidgets
pip install pyvista
Create venv kernel in Jupyterlab
pip install ipykernel
#create kernel
python -m ipykernel install --user --name=[your virtual environment name]
Run Jupyterlab using command jupyter lab outside of the venv.
Use the following code as an example or the code pasted above in description along with the .zip file:
import ipywidgets as widgets
widgets.IntSlider()
Context
- ipywidgets version 8.0.2
- Operating System and version: Ubuntu 22.04.1 LTS x86_64
- Browser and version: Firefox 105.0
- itkwidgets 0.32.2
Troubleshoot Output
$PATH: /home/nika/.venvs/venv3_9/bin /home/nika/.local/bin /usr/local/sbin /usr/local/bin /usr/sbin /usr/bin /sbin /bin /usr/games /usr/local/games /snap/bin /snap/bin
sys.path: /home/nika/.venvs/venv3_9/bin /usr/lib/python39.zip /usr/lib/python3.9 /usr/lib/python3.9/lib-dynload /home/nika/.venvs/venv3_9/lib/python3.9/site-packages
sys.executable: /home/nika/.venvs/venv3_9/bin/python3.9
sys.version: 5.9.14 (main, Sep 7 2022, 23:43:48) [GCC 11.2.0]
platform.platform(): Linux-5.15.0-48-generic-x86_64-with-glibc2.35
which -a jupyter: /home/nika/.venvs/venv3_9/bin/jupyter /home/nika/.local/bin/jupyter /usr/bin/jupyter /bin/jupyter
pip list: Package Version ------------------ ----------- aiohttp 3.8.3 aiosignal 1.2.0 appdirs 1.4.4 asttokens 2.0.8 async-timeout 4.0.2 attrs 22.1.0 backcall 0.2.0 charset-normalizer 2.1.1 colorcet 3.0.0 contourpy 1.0.5 cycler 0.11.0 debugpy 1.6.3 decorator 5.1.1 entrypoints 0.4 executing 1.0.0 fonttools 4.37.3 frozenlist 1.3.1 idna 3.4 imageio 2.22.0 ipydatawidgets 4.3.2 ipykernel 6.15.3 ipympl 0.9.2 ipython 8.5.0 ipython-genutils 0.2.0 ipywidgets 8.0.2 itk-core 5.2.1.post1 itk-filtering 5.2.1.post1 itk-meshtopolydata 0.8.1 itk-numerics 5.2.1.post1 itkwidgets 0.32.2 jedi 0.18.1 jupyter_client 7.3.5 jupyter-core 4.11.1 jupyterlab-widgets 3.0.3 kiwisolver 1.4.4 matplotlib 3.6.0 matplotlib-inline 0.1.6 multidict 6.0.2 nest-asyncio 1.5.5 numpy 1.23.3 packaging 21.3 param 1.12.2 parso 0.8.3 pexpect 4.8.0 pickleshare 0.7.5 Pillow 9.2.0 pip 22.0.4 prompt-toolkit 3.0.31 psutil 5.9.2 ptyprocess 0.7.0 pure-eval 0.2.2 pyct 0.4.8 Pygments 2.13.0 pyparsing 3.0.9 python-dateutil 2.8.2 pyvista 0.36.1 pyzmq 24.0.1 scooby 0.6.0 setuptools 58.1.0 six 1.16.0 stack-data 0.5.0 tornado 6.2 traitlets 5.4.0 traittypes 0.2.1 vtk 9.1.0 wcwidth 0.2.5 widgetsnbextension 4.0.3 wslink 1.8.2 yarl 1.8.1 zstandard 0.18.0
Command Line Output
Browser Output
JupyterLab
- JupyterLab version: JupyterLab v3.4.7
Installed Labextensions
JupyterLab v3.4.7
/home/nika/.local/share/jupyter/labextensions
jupyterlab-datawidgets v7.1.1 enabled OK
jupyterlab_pygments v0.2.2 enabled OK (python, jupyterlab_pygments)
ipyevents v2.0.1 enabled OK
jupyter-matplotlib v0.11.2 enabled OK
jupyter-threejs v2.4.0 enabled OK (python, pythreejs)
ipycanvas v0.13.1 enabled OK
Other labextensions (built into JupyterLab)
app dir: /home/nika/.local/share/jupyter/lab
@jupyter-widgets/jupyterlab-manager v5.0.3 enabled OK
imjoy-jupyter-extension v0.3.0 enabled OK
itkwidgets v0.32.2 enabled OK
This looks like the same error as #3598
On a hunch, can you run JupyterLab after setting the JUPYTER_PREFER_ENV_PATH environment variable to 1?
JUPYTER_PREFER_ENV_PATH=1 jupyter lab
It seems that the kernel is ipywidgets 8, but the frontend has the ipywidgets 7 javascript. From the paths for your extensions, it looks like a user extension may be shadowing the appropriate version.
On a hunch, can you run JupyterLab after setting the JUPYTER_PREFER_ENV_PATH environment variable to 1?
JUPYTER_PREFER_ENV_PATH=1 jupyter labIt seems that the kernel is ipywidgets 8, but the frontend has the ipywidgets 7 javascript. From the paths for your extensions, it looks like a user extension may be shadowing the appropriate version.
After trying the above, the error is still the same. Additional info on paths using jupyter --paths --debug after using the JUPYTER_PREFER_ENV_PATH=1 jupyter lab command as well as just export JUPYTER_PREFER_ENV_PATH=1 command in venv:

This looks like the same error as #3598
Before posting the issue I tried the answer given on this issue but it did not change anything for me after reinstalling. I have also tried to follow the answers on issue #3559 and issue #3577.