Jupyter: select kernel on remote machine gives error
See original GitHub issueEnvironment 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
- 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:
- 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:
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]
- XXX
Logs
Output for Jupyter
in the Output
panel (View
→Output
, change the drop-down the upper-right of the Output
panel to Jupyter
)
XXX
Issue Analytics
- State:
- Created 3 years ago
- Comments:15 (6 by maintainers)
Top GitHub Comments
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.
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.