I try to pass a javascript variable to python in a jupyter notebook, as described in How to pass variables from javascript to python in Jupyter?
Somehow the IPython.notebook.kernel.execute("foo=97") seems not to work, but IPython itself works.
Here my code from the jupyter notebook
# [1]
from IPython.display import HTML
# [2]
HTML('''<script>console.log('foo=101')</script>''')
# [3]
HTML('''
<script type="text/javascript">
IPython.notebook.kernel.execute("foo=97")
</script>
''')
Executing cell [2] after cell [1] shows in the console foo=101. Executing cell [3] shows this error in the console
VM1448:2 Uncaught ReferenceError: IPython is not defined
at <anonymous>:2:5
at t.attachWidget (jlab_core.e37d4bbc8c984154bc26.js?v=e37d4bbc8c984154bc26:2:1594384)
at t.insertWidget (jlab_core.e37d4bbc8c984154bc26.js?v=e37d4bbc8c984154bc26:2:1593735)
at j._insertOutput (jlab_core.e37d4bbc8c984154bc26.js?v=e37d4bbc8c984154bc26:2:925178)
at j.onModelChanged (jlab_core.e37d4bbc8c984154bc26.js?v=e37d4bbc8c984154bc26:2:922355)
at m (jlab_core.e37d4bbc8c984154bc26.js?v=e37d4bbc8c984154bc26:2:1560386)
at Object.l [as emit] (jlab_core.e37d4bbc8c984154bc26.js?v=e37d4bbc8c984154bc26:2:1560046)
at e.emit (jlab_core.e37d4bbc8c984154bc26.js?v=e37d4bbc8c984154bc26:2:1558291)
at c._onListChanged (jlab_core.e37d4bbc8c984154bc26.js?v=e37d4bbc8c984154bc26:2:918778)
at m (jlab_core.e37d4bbc8c984154bc26.js?v=e37d4bbc8c984154bc26:2:1560386)
Any ideas how to solve my problem?
My jupyter setup:
IPython : 8.6.0
ipykernel : 6.17.1
ipywidgets : 8.1.1
jupyter_client : 7.4.7
jupyter_core : 5.0.0
jupyter_server : 1.23.2
jupyterlab : 3.5.0
nbclient : 0.7.0
nbconvert : 7.2.5
nbformat : 5.7.0
notebook : 6.5.2
qtconsole : not installed
traitlets : 5.5.0
kernel.execute()like you. What are you trying to do that you thought you could ...