How to render LaTeX ipywidgets description in VScode? - visual-studio-code

I am trying to run some interactive cells in a Jupyter notebook on VScode but LaTeX on sliders descriptors is not rendered at all, while in matplotlib plots it's rendered correctly.
Opening a jupyter notebook in the browser all the LaTeX labels are rendered correctly instead.
I checked out this other thread but it looks as the basic requirements are ok. Here is my jupyter --version output
Selected Jupyter core packages...
IPython : 8.4.0
ipykernel : 6.15.2
ipywidgets : 7.7.1
jupyter_client : 7.4.7
jupyter_core : 4.11.2
jupyter_server : 1.18.1
jupyterlab : 3.5.0
nbclient : 0.5.13
nbconvert : 6.5.4
nbformat : 5.5.0
notebook : 6.5.2
qtconsole : 5.3.2
traitlets : 5.4.0
Code:
import ipywidgets as widgets
import matplotlib.pyplot as plt
%matplotlib widget
latext = "$n_\\alpha$"
widgets.FloatSlider(min=1., max=4.0, value=2, step = 0.01, description = latext)
plt.plot(range(10))
plt.xlabel(latext)
plt.show()
Expected behaviour:

Related

Jupyter not found when checked with quarto in Mac

I installed the Jupyter with brew, and when I type
jupyter --version
I got the following
IPython : 8.8.0
ipykernel : 6.16.0
ipywidgets : not installed
jupyter_client : 7.3.5
jupyter_core : 4.11.1
jupyter_server : 1.19.1
jupyterlab : 3.4.8
nbclient : 0.6.8
nbconvert : 7.1.0
nbformat : 5.6.1
notebook : 6.4.12
qtconsole : not installed
traitlets : 5.8.0
But when I checked the Jupyter with quarto:
quarto check jupyter
I got the following
[✓] Checking Python 3 installation....OK
Version: 3.9.6
Path: /Library/Developer/CommandLineTools/usr/bin/python3
Jupyter: (None)
Jupyter is not available in this Python installation.
Install with python3 -m pip install jupyter
It seems that the Jupyter installed via brew could not be found by the quarto.
Is there a way to fix this with out reinstalling the Jupyter with pip?
Thanks

Problems with ipywidgets when importing vaex

I am trying to import vaex after pip installation but the following problem appears an is not solved even after I have done a pip install for the specific 7.6.0 version of ipywidgets in the jupyter notebook where I am (naively typed !pip -upgrade ipywidgets and !pip install ipywidgets==7.6.0).
ContextualVersionConflict: (ipywidgets 7.5.1 (/Users/federiconutarelli/opt/anaconda3/lib/python3.8/site-packages), Requirement.parse('ipywidgets<8,>=7.6.0'), {'ipympl', 'ipyleaflet'})
Is there a way to solve the issue here from jupyter?

Open ipynb on Visual Studio Code, display json

When I open an ipynb file, I just see a json file. I tested with all files of :
https://github.com/MicrosoftLearning/mslearn-ai900.git
I have on my machine :
Python 3.9.6 installed
Installed with pip command : jupyterlab, notebook and voila
On Visual Studio Code (version 1.59.0) :
Python 3.9.6 64-bit is the current interpreter.
I can create a new notebook : "CTRL+SHIFT+P --> Jupyter : Create new blank notebook"
and I saw on the down-right "Jupyter Server:local". I can execute code : print("Hello, Python!"), but when I try to save file, I have this error :
Failed to register 'Untitled-1' : File name file:///*ThePathToSave*/Test.ipynb is not supported by Jupyter.
Extensions installed :
Jupyter v2021.8.1195043623
Pylance v2021.8.1
Python v2021.8.1105858891
List of kernel : (command) jupyter kernelspec list
Available kernels:
.net-csharp C:\Users\antho\AppData\Roaming\jupyter\kernels\.net-csharp
.net-fsharp C:\Users\antho\AppData\Roaming\jupyter\kernels\.net-fsharp
.net-powershell C:\Users\antho\AppData\Roaming\jupyter\kernels\.net-powershell
python3 c:\python\python39\share\jupyter\kernels\python3
Thanks for your help.
I re-install all Visual Studio Code.
I followed this answer to uninstall 'completely' VS Code :
https://debug.to/1074/how-to-uninstall-vs-code-completely
and after, I re-install Visual Studio Code.
Now I can open all files.
Thanks to #IanHuff

Visual Studio Code does not render ipywidgets correctly

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
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
There two things you can explore.
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.
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.

jupyter ImportError: cannot import name 'constants' from partially initialized module 'zmq.backend.cython'

I recently upgraded jupyter, but now I get
ImportError: cannot import name 'constants' from partially initialized module 'zmq.backend.cython'
when I run for instance jupyter-notebook or jupyter notebook
and pip install --upgrade pyzmq did not solve the issue
any idea?
Thanks
ps: I am on Mac OS 10.15.5 , with jupyter --v:
jupyter core : 4.6.3
jupyter-notebook : 6.0.3
qtconsole : 4.5.5
ipython : 8.0.0.dev
ipykernel : not installed
jupyter client : not installed
jupyter lab : 1.2.3
nbconvert : 5.6.1
ipywidgets : not installed
nbformat : 5.0.4
traitlets : 4.3.3
I had the same issue and below fixed my problem:
pip uninstall pyzmq
pip install pyzmq
This actually worked. If you are launching jupyter-notebook from a venv and you get this error message, just pip unistall pyzmg and pip install pyzmg. You should be fine.