Launch ipykernel in VSCode¶
VSCode can start ipykernel (and run Jupyter notebook) from a Singularity container.
Here is a simple example setup.
- Build or pull container that has
ipykernelinstalled. Note: You do not need to install jupyter into the Python environment you want to use. Only the IPyKernel package is required to launch a Python process as a kernel and execute code against your notebook (pip install ipykernel). Visit the Jupyter extension wiki to learn more.
~/.local/share/jupyter/kernels/singularity-kernel01/kernel.json file with content like this on the computer where the container is. Make sure you match the location of the container. Below is a working example for Pelle.
{
"argv": [
"apptainer", "exec",
"--bind", "/crex,/gorilla,/proj,/sw,/run/user","--nv",
"/proj/sinapp/nobackup/00.workshop/pytorch_22.03-py3.sif",
"python", "-m", "ipykernel_launcher", "-f", "{connection_file}"
],
"display_name": "Pytorch_22.03",
"language": "python"
}
4. Open a Jupyter notebook or create a new one.
5. "Select Kernel", then "Jupyter Kernel"...

6. Select from the predefined Jupyter kernels..

7. Run...
Note
On Pelle, users are not allowed to ssh to the compute node where the job is running, so this approach will not work to start kernel on a compute node. Instead,
1. Start jupyter with jupyter --ip 0.0.0.0 --no-browser in an interactive session
2. From VSCode remote session on Pelle, chose "Existing Jupyter Server" when selecting a kernel.
Make sure, you point to the correct address which includes the node address, for example http://p2033.uppmax.uu.se:8888/lab?token=28026d8d41adccf863f01c471260c7fc5b20b6441872a79a