Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set a python variable using javascript in JupyterLab

In jupyter notebook I can set a Python variable using javascript by doing

%%javascript
IPython.kernel.execute("foo=56");

However in Jupyter Lab I get "Javascript Error: IPython is not defined"

How can I set a python variable using javascript in Jupyter lab, in a similar way to Jupyter notebook?

like image 446
Hugo Antunes Avatar asked Mar 23 '26 16:03

Hugo Antunes


1 Answers

IPython is a JavaScript object which does not exist in JupyterLab, only in Notebooks. See this question:

Executing Java script code in JupyterLab gives error

And also this lengthy bug report/discussion on GitHub:

https://github.com/jupyterlab/jupyterlab/issues/5660

TL;DR: Currently there is no approved solution to this, but people are working on it.

like image 169
jpunkt Avatar answered Mar 26 '26 06:03

jpunkt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!