This part is like you are taking pyscript configuration code and expecting it to work in Jupyter? I’m not sure why you’d do that? As Afonit references, installing packages is a separate process that you’d do.
You’d follow standard Python and Jupyter practices to install packages in the environment where your kernel is running. One of the most straightforward options is to add a new cell above the ipywidgets code that afonit provided. In that new cell you’d enter the following:
%pip install pandas numpy
Then run that cell. That magic symbol in combination with the pip install
will help insure it installs into the environment where the kernel is running. (That install command will work in JupyterLite, too.) Then if the install goes successfully, restart the kernel and you should be able to run the code import pandas as pd
and see it imported without error. Similar with import numpy as np
. Ipywidgets makes more changes in more places and so it isn’t as simple to install that way. (Sometimes it will work that way if you add in additional hard refresh of your browser page. I also recommend restarting both Jupyter and your browser, maybe even the entire machine, plus the hard refresh on the browser page after the ipywidgets install step.) You didn’t ask about that one and so hopefully that means you already have that covered. Once you have those installed afonit’s code should work.
See more about the modern %pip install
command here.