vscode-jupyter: Wrong kernel name in metadata kernelspec when using kernel from virtualenv

Environment data

  • VS Code version: 1.63.2
  • Jupyter Extension version (available under the Extensions sidebar): v2021.11.1001550889
  • Python Extension version (available under the Extensions sidebar): v2021.12.1559732655
  • OS (Windows | Mac | Linux distro) and version: Ubuntu 18.04
  • Python: Python 3.8
  • Type of virtual environment used: virtualenv
  • Jupyter server running: Local

Expected behaviour

I created a new virtual environment with the name venv_2.

virtualenv venv_2 --python=python3.8

I add kernel to that venv:

python -m ipykernel install --user --name=venv_2

I created a new ipynb file in the VS Code and select kernel to venv_2 in the top right corner.

When I check the file of the notebook in the text editor I see the wrong kernelspec in metadata, it has name set to python3 but it should be set to venv_2.

The contents of the notebook:

... the rest of the notebook ...
"metadata": {
  "kernelspec": {
   "display_name": "Python 3.8.0 64-bit ('venv_2': virtualenv)",
   "language": "python",
   "name": "python3"
  },

It should be

... the rest of the notebook ...
"metadata": {
  "kernelspec": {
   "display_name": "Python 3.8.0 64-bit ('venv_2': virtualenv)",
   "language": "python",
   "name": "venv_2"
  },

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 22 (16 by maintainers)

Most upvoted comments

No apologies necessary, glad that you were able to verify this and get back to us. Thanks again for the confirmation.

@DonJayamanne sorry for the confusion. I’ve started VS Code after machine restart and looks like it is working!

vs-code-reproduce

Thank you very much! Closing the issue.

@pplonski Thanks for providing the information, I’m confused with the steps used to repro this issue, please could you provide the following information:

  • Lets start this test from scratch
  • Please reload VS Code
  • Create a new notebook file (ipynb with the contents you expect, e.g. ensure you have the desired kernelspec name and display name)
    • Please remove the hash information (this is added by VS Code, hence this must be removed) & the file name also changed
  • Please provide the ipynb file used for testing (before you edit it in vscode), i’d like to see what is inside the ipynb before it gets updated by VS Code
  • Please provide a screenshot of the notebook with the selected kernel displayed on the top right handside of the notebook
  • Run a cell, and you will get prompted to select a kernel (please provide a screenshot of this list)
  • Save the notebook, please upload the ipynb file (I’d like to see what it gets updated to)
  • Please upload the contents of the jupyter output panel (please provide all of the logs)

Here’s the partial working branch. https://github.com/microsoft/vscode-jupyter/tree/rchiodo/use_kernel_name

I think we could either:

  • Not preemptively generate a kernelspec from the active interpreter
  • Update the controller after the new list comes back