gasar8
gasar8

Reputation: 314

Setting up jupyter kernel in remote VSCode notebook

I am trying to run some notebooks in my virtual environment in the VSCode (remotely connected). I install the venv as usual via python3 -m venv <venv-name>, activate it and install all the needed modules. When I run which ipython I get the one from the venv so I install the kernel via ipython kernel install --name "<name>" --user and it is successfully created in ~/.local/share/jupyter/kernels/ directory and the kernel.json points to the venv python. Then I open the VSCode and select both the Python: Select Interpreter and Jupyter: Select Interpreter to start Jupyter server to point to the virtual environment's python, sth. like .../<venv-name>/bin/python3.

However, when I try to run the cell it wants me to select kernel (I can also do it myself in the upper right corner of the VSCode), but my newly created kernel is not there. There are only two (same) ones from usr/bin/python.

It is really strange since twice in two days my kernel magically appeared for one notebook and worked as desired, but when I opened a new notebook, my kernel was gone again. I tried to remove/reinstall kernels, venvs, VSCode's Python and Jupyter extensions but nothing helped. Any suggestions?

For now, I start the kernel in remote command-line via jupyter notebook --no-browser --ip=<ip> and then insert the connection link to Jupyter Server in the bottom right corner of the VSCode status bar but am wondering if there is an easier way since all the stuff (except VSCode) is on a remote machine?

Upvotes: 11

Views: 13560

Answers (2)

Jake Stevens-Haas
Jake Stevens-Haas

Reputation: 1696

Pip installing jupyter and creating an ipykernel for your virtual environment should allow the Jupyter VSCode extension to see that environment in the "Notebook: Select Notebook Kernel" dropdown. You may need to restart VSCode (or just the extension?)

According to the Jupyter VSCode extension docs

A Visual Studio Code extension that... allows any Python environment to be used as a Jupyter kernel. This is NOT a Jupyter kernel--you must have Python environment in which you've installed the Jupyter package.

I also tried just creating the kernel on the SSH server, but the Jupter extension still didn't pick it up as an option for "Notebook: Select Notebook Kernel" until I pip installed jupyter and restarted VSCode.

System info: VSCode 1.79.2 for Linux x64, into an ubuntu SSH server. Jupyter VSCode extension v2023.5.1101742258

Upvotes: 1

Ning Ben
Ning Ben

Reputation: 65

This way is not easy. You can set up Jupyter Kernel easily. Firstly, using ssh to connect to the remote server. Secondly, open Command Palette (⇧⌘P) and enter Python: Select Interpreter, you can directly connecting to remote kernel.

resource: https://code.visualstudio.com/docs/datascience/jupyter-notebooks

Upvotes: 3

Related Questions