IPython not defined from Javascript

I am developing a Python package that is supposed to run in jupyter lab. I need to retrieve some information from a Javascript library that runs within a Ipython.display(HTML(…)). I have seen examples on the internet of people using IPython within Javascript to do this sort of communication. For example, I should be able to do something like this and execute any code from the kernel:

import IPython.display as ipd

ipd.display(ipd.Javascript(“”“IPython.notebook.kernel.execute(‘print(“Hello World!”)’);”“”))

However, I’m getting a ‘IPython is not defined.’ issue. I have scoured the internet for a solution but I could not find anything that worked. Does anybody know some workaround to fix this issue? Thanks.

N.B. There is a solved thread with a very similar title but it is not the same issue. My problem has nothing to do with matplotlib.

Hopefully, you have seen that the Jupyter ecosystem has changed a lot in the last year or so. If not , go here and look at the bottom half of my reply there. What you are asking about pertains to Jupyter Notebook 7+ and JupyterLab being on JupyterLab components. Most of the posts you find on the internet pertain to older versions of Jupyter.

This example you first invoke using IPython.notebook.kernel.execute() is indeed one of the things that has changed. This is has been covered here on this forum already here and here.

See also:

Thanks for the reply. By now, I have worked out a hacky solution to send information from JS to Python. I will share it here later after refining it a bit.

1 Like