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.

Cannot Switch to Different Python kernel

See original GitHub issue

Environment data

  • VS Code version: Version: 1.54.3 (Universal) Commit: 2b9aebd5354a3629c3aba0a5f5df49f43d6689f8
  • Jupyter Extension version (available under the Extensions sidebar): v2021.3.619093157
  • Python Extension version (available under the Extensions sidebar): v2021.3.658691958
  • OS (Windows | Mac | Linux distro) and version: macOS Big Sur 11.2.3 (ARM 64 arch)
  • Python and/or Anaconda version: 3.8.2, conda 4.9.2
  • Type of virtual environment used (N/A | venv | virtualenv | conda | …): conda
  • Jupyter server running: Local

Expected behaviour

When selecting a specific Python Kernel (which are found) Jupyter VS Code should use that one, at least after a restart. In my workspace settings, I have explicitly set the option "python.pythonPath": "/opt/homebrew/Caskroom/miniforge/base/envs/nlpsimple/bin/python", where nlpsimple is my desired environment.

Actual behaviour

Running sys.executable outputs '/opt/homebrew/Caskroom/miniforge/base/bin/python', so apparently VS Code Jupyter is unable to switch to a different environment. I have switched to my desired environment in the internal terminal before re-starting the kernel and re-running this command with the same result.

It seems that Jupyter VS Code tries to use my system installation of Python to start the IPython Kernel. However, my environments use 3.8 since I need PyTorch, while my system installation has 3.9 – see logs below.

Steps to reproduce:

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

  1. I am using Jupyter VS Code in a pretty fresh install since VS Code just recently released as stable for M1 Macs. Other than the above-mentioned setting in my workspace, there is nothing I changed with the base settings, and I have not yet worked using VS Code Jupyter in this new installation (which should be self-contained from the Insiders edition I was using before)
  2. The environments were installed before, however.

Logs

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

[I 09:51:42.430 NotebookApp] Kernel shutdown: a9c72ff0-b1eb-44ee-b83e-a3ba17234563
> /opt/homebrew/Caskroom/miniforge/base/envs/nlpsimple/bin/python ~/.vscode/extensions/ms-toolsai.jupyter-2021.3.619093157/pythonFiles/pyvsc-run-isolated.py -c "import ipykernel"
[I 09:51:43.013 NotebookApp] Kernel started: 4f1478ad-4875-4935-b196-5dd89c57c141, name: python3
[W 09:51:43.017 NotebookApp] delete /t-20bc9970-c10a-498b-9b6a-b8f48d942aff.ipynb
Error 2021-03-19 09:54:42: KernelSpec has interpreter information, however a matching interpreter could not be found for /opt/homebrew/opt/python@3.9/bin/python3.9
Error 2021-03-19 09:54:43: KernelSpec has path information, however a matching interpreter could not be found for /opt/homebrew/opt/python@3.9/bin/python3.9
Error 2021-03-19 09:59:19: KernelSpec has interpreter information, however a matching interpreter could not be found for /opt/homebrew/opt/python@3.9/bin/python3.9
> /opt/homebrew/Caskroom/miniforge/base/envs/nlpsimple/bin/python ~/.vscode/extensions/ms-toolsai.jupyter-2021.3.619093157/pythonFiles/pyvsc-run-isolated.py -c "import ipykernel"
> /opt/homebrew/Caskroom/miniforge/base/envs/nlpsimple/bin/python ~/.vscode/extensions/ms-toolsai.jupyter-2021.3.619093157/pythonFiles/pyvsc-run-isolated.py pip list
Error 2021-03-19 09:59:20: KernelSpec has path information, however a matching interpreter could not be found for /opt/homebrew/opt/python@3.9/bin/python3.9
> /opt/homebrew/Caskroom/miniforge/base/envs/nlpsimple/bin/python ~/.vscode/extensions/ms-toolsai.jupyter-2021.3.619093157/pythonFiles/pyvsc-run-isolated.py pip list

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
DonJayamannecommented, Mar 19, 2021

Thanks for filing this issue. I believe we have addressed this in our current development version of the extension.

In order to validate the fixes please could you:

  • Install VS Code Insiders
  • Install the Jupyter extension Test and let me know if this works.

Thanks

1reaction
njbamboocommented, Mar 19, 2021

I have the same problem. The only way to solve it is to change the jupyter server from the vscode default to the link given by jupyter notebook in cmd/powershell (I opened another jupyter notebook by command). The link is something like “http://localhost:8888/?token=xxxxxxxx or http://127.0.0.1:8888/?token=xxxxxxx”. When I changed the jupyter server to this one, I can import every module. Also I found a strange thing : by changing the jupyter serve between the above two choices, when you switch back to vscode’s default server at some time point (seem to be random), it will be possible to import the module again!

Read more comments on GitHub >

github_iconTop Results From Across the Web

cannot switch kernel in vscode ipynb interface #4147 - GitHub
open a notebook in vscode (with python extension); try to switch between the kernels in the vscode notebook interface; diagnose with !which ...
Read more >
How to change jupyter kernel from Python 2 to python 3?
The interesting part: if you want to switch between kernels (py2-py3) in the same notebook, you need to run, conda install nb_conda.
Read more >
How to change the kernel version in Jupyter Python Notebooks?
Click on " Change kernel " from the drop down box that appears and chose the version that is required.
Read more >
Jupyter Notebook Kernels: How to Add, Change, Remove
Add, remove and change Kernels to use with Jupyter notebook.
Read more >
Change an Image or a Kernel - Amazon SageMaker
The following screenshot shows the menu from a Studio notebook. The current SageMaker kernel and image are displayed as Python 3 (Data Science),...
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