question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Jupyter: select kernel on remote machine gives error

See original GitHub issue

Environment data

  • VS Code version: 1.53.2
  • Jupyter Extension version (available under the Extensions sidebar): v2021.2.576440691
  • Python Extension version (available under the Extensions sidebar): v2021.2.576481509
  • OS (Windows | Mac | Linux distro) and version: client is macOS 11.2.1 , remote is popOS 20.10
  • Python and/or Anaconda version: miniconda 4.9.2 on both machines, variety of python versions in different conda envs
  • Type of virtual environment used (N/A | venv | virtualenv | conda | …): conda
  • Jupyter server running: Remote jupyter lab v3.0.7 (using ipython 7.20.0, python 3.9.1)

Expected behaviour

After selecting to connect to remote jupyter kernel and restarting vscode, I would expect the “select interpreter or start jupyter server” option in command palette to now list existing sessions on the remote machine and give the option to start a new session, allowing me to select a kernel among the available conda environments.

Actual behaviour

the above mentioned option still shows local kernels. in order to actually connect to remote kernels:

.py file

  • run line/cell/file in interactive window
  • interactive window pops up, it has selected a random kernel from the conda environments on the remote machine (i say random but it seems to be the same every time so far, so i guess it selects based on something, it’s not the kernel/env name)
  • there’s no “select kernel” option in command palette a la #4479
  • i can click the kernel name in the top right of the interactive window and get a list of available kernels and running sessions
  • selecting one, gives me a prompt to install ipykernel in the local conda/python interpreter currently selected
Screenshot 2021-02-18 at 18 57 43
  • this doesn’t really make sense to me, but fine, install it if you want
  • after it has opened a vscode terminal window and installed ipykernel and a bunch of other packages on my local machine, the interactive window is now switched to the conda environment that the jupyter server is running from, not the kernel i selected (i could confirm with ipython help() and modules commands)
  • trying again to select a remote kernel for the interactive menu, just restarts the jupyter server conda kernel

.ipynb file

  • after fiddling around with the above steps for .py files for this report, creating an empty .ipynb file and then selecting jupyter kernel via command palette magically worked. the correct kernel/conda env is used. it didn’t before for .ipynb files (see the above linked issue). it now worked for the .py file as well.
  • restarted vscode to see if it would work again, but it did not
  • restarted the jupyter server
  • restarted vscode
  • selected to use remote kernel, it asked to restart vscode
  • now it cannot connect to remote kernel at all, although i’m specifying the new token
  • it seems it’s still using the old token, because in the command palette list i see the old token stated . there’s also 403 forbidden messages in jupyter server log
  • vscode seems to have stored an entire jupyter session in memory, as every time i try to restart vscode, it opens empty and as soon as i create a new empty .ipynb file all the old .ipynb files i used for testing pops up
  • i find command “clear jupyter server list” in command palette and run it
  • i also run “clear editor history”
  • restart vscode and create new empty .ipynb file
  • all the old .ipynb files pop up again and no connections possible
  • however, now jupyter server says 405 post error so i guess something changed
  • only content of the .vscode/settings.json ist still the “jupyter.jupyterServerType”: “remote”
  • create new fodler and open that instead and create .ipynb file there
  • vscode has now randomly selected a new local python interpreter among my conda environments (as seen in screenshot from before it was ‘base’ on python 3.7 and now it’s ‘pdoc’ on python 3.9.1)
  • i select again to connect to remote kernel and vscode asks to restart
  • no ask to install ipykernel locally because i already did than in the pdoc environment an hour ago when i was trying this the first time around
  • notebook kernel status now says:
Screenshot 2021-02-18 at 19 50 44
  • nothing happens when i click on the “jupyter server” text
  • jupyter output log:
Error 2021-02-18 19:42:33: SessionManager cannot enumerate kernelspecs. Returning default {}.
Connecting to Jupyter server at http://servername/lab
Error 2021-02-18 19:42:34: Failed to change kernel [t [Error]: Invalid response: 405 Method Not Allowed
	at /Users/username/.vscode/extensions/ms-toolsai.jupyter-2021.2.576440691/out/client/node_modules/@jupyterlab/services.js:3:366901
	at processTicksAndRejections (internal/process/task_queues.js:97:5)
	at async w.createBackingFile (/Users/username/.vscode/extensions/ms-toolsai.jupyter-2021.2.576440691/out/client/extension.js:49:555897)
	at async w.createSession (/Users/username/.vscode/extensions/ms-toolsai.jupyter-2021.2.576440691/out/client/extension.js:49:556428)
	at async w.createNewKernelSession (/Users/username/.vscode/extensions/ms-toolsai.jupyter-2021.2.576440691/out/client/extension.js:49:554756)
	at async w.connect (/Users/username/.vscode/extensions/ms-toolsai.jupyter-2021.2.576440691/out/client/extension.js:49:554404)
	at async m.startNew (/Users/username/.vscode/extensions/ms-toolsai.jupyter-2021.2.576440691/out/client/extension.js:49:549756)
	at async _.connect (/Users/username/.vscode/extensions/ms-toolsai.jupyter-2021.2.576440691/out/client/extension.js:49:520500)
	at async /Users/username/.vscode/extensions/ms-toolsai.jupyter-2021.2.576440691/out/client/extension.js:32:653463] {
  response: N [Response] {
    size: 0,
    timeout: 0,
    [Symbol(Body internals)]: { body: [PassThrough], disturbed: false, error: null },
    [Symbol(Response internals)]: {
      url: 'http://servername/lab/api/contents/?1613673754461',
      status: 405,
      statusText: 'Method Not Allowed',
      headers: [P [Headers]],
      counter: 0
    }
  }
}
  • i try to run a cell in the notebook and receive this error:
Screenshot 2021-02-18 at 19 49 09

the jupyter output mentioned is the following:

Error 2021-02-18 19:48:01: DataScience Error [i [Error]: 
	at new t.WrappedError (/Users/username/.vscode/extensions/ms-toolsai.jupyter-2021.2.576440691/out/client/extension.js:1:153031)
	at /Users/username/.vscode/extensions/ms-toolsai.jupyter-2021.2.576440691/out/client/extension.js:32:654971
	at processTicksAndRejections (internal/process/task_queues.js:97:5)

Error: Kernel Python 3 is not usable. Check the Jupyter output tab for more information.
	at w.createNewKernelSession (/Users/username/.vscode/extensions/ms-toolsai.jupyter-2021.2.576440691/out/client/extension.js:49:554995)
	at processTicksAndRejections (internal/process/task_queues.js:97:5)
	at async w.connect (/Users/username/.vscode/extensions/ms-toolsai.jupyter-2021.2.576440691/out/client/extension.js:49:554404)
	at async m.startNew (/Users/username/.vscode/extensions/ms-toolsai.jupyter-2021.2.576440691/out/client/extension.js:49:549756)
	at async _.connect (/Users/username/.vscode/extensions/ms-toolsai.jupyter-2021.2.576440691/out/client/extension.js:49:520500)
	at async /Users/username/.vscode/extensions/ms-toolsai.jupyter-2021.2.576440691/out/client/extension.js:32:653463] {
  category: 'invalidkernel',
  originalException: [c [Error]: Kernel Python 3 is not usable. Check the Jupyter output tab for more information.
  	at w.createNewKernelSession (/Users/username/.vscode/extensions/ms-toolsai.jupyter-2021.2.576440691/out/client/extension.js:49:554995)
  	at processTicksAndRejections (internal/process/task_queues.js:97:5)
  	at async w.connect (/Users/username/.vscode/extensions/ms-toolsai.jupyter-2021.2.576440691/out/client/extension.js:49:554404)
  	at async m.startNew (/Users/username/.vscode/extensions/ms-toolsai.jupyter-2021.2.576440691/out/client/extension.js:49:549756)
  	at async _.connect (/Users/username/.vscode/extensions/ms-toolsai.jupyter-2021.2.576440691/out/client/extension.js:49:520500)
  	at async /Users/username/.vscode/extensions/ms-toolsai.jupyter-2021.2.576440691/out/client/extension.js:32:653463] {
    category: 'invalidkernel',
    kernelConnectionMetadata: {
      kernelSpec: [a],
      interpreter: [Object],
      kind: 'startUsingKernelSpec'
    }
  }
}

When i now check the jupyter server logs I realise that the 405 message is referring to vscode apparently trying to connect using the exact same kernelspec/session as it successfully used once, in the first step of this now hilariously long story.

LabApp] 405 POST /lab/api/contents/?1613674081782

sanity check

both jupyterlab itself (accessing it directly by browser) and atom can connect and list and start kernels without any issues. but when checking i noticed that there’s now a new kernel “Python 3” listed. did vscode install/rename this kernel? i can’t recall seeing it before.

end of story/cliffhanger

sorry about not cleaning up this report to make it a bit … well, shorter. i wrote it as i investigated and now i’m tired and hungry. it’s funny but this kind of thing happens every time i decide to try vscode again. i’m probably cursed. so maybe just close this issue tagged “disturbing aura around user. won’t fix”, a.k.a. pebkac.

Steps to reproduce:

[NOTE: Self-contained, minimal reproducing code samples are extremely helpful and will expedite addressing your issue]

  1. XXX

Logs

Output for Jupyter in the Output panel (ViewOutput, change the drop-down the upper-right of the Output panel to Jupyter)

XXX

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:15 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
lseongjoocommented, Nov 4, 2021

I thought that I had the same problem. But I checked the extensions, Python and Pylance extension can be installed on remote. After installing those extensions to SSH server, kernel selection is just like on the server. I have been working on the SSH host with vscode too and there are no problems. So I don’t know why, but somewhat it works.

1reaction
sarobertscommented, Mar 5, 2021

I just read through the previous comments, and noted that I was running the VS code release 1.54.1, not the insiders build. I just now installed the insiders build, got everything set up, spent about 5 minutes looking for where the button moved to change the kernel/environment, and tested it. It seems to work just fine now! I can easily switch between kernels/environments in a notebook.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Fix Kernel Error in Jupyter Notebook
So, a kernel error occurs when Jupyter fails to connect with a specific version of Python. When the system encounters difficulties locating ...
Read more >
Failed to start the Kernel - Jupyter in VS Code - Stack Overflow
I got the same error message because the jupyter package was missing in my selected environment. pip install jupyter.
Read more >
How to fix Kernel Error or broken Python in Jupyter Notebook
TL;DW BELOW! If you delete or upgrade your python version, you might get a Kernel Error when trying to use Jupyter Notebooks!
Read more >
What to do when things go wrong - The Jupyter Notebook
Jupyter fails to start​​ If Jupyter gives an error that it can't find notebook , check with pip or conda that the notebook...
Read more >
DataSpell - Manage Jupyter notebook servers - JetBrains
Managed server – a Jupyter server that is automatically launched by ... You can also see the automatically created server kernel in the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found