2

I have created a virtual environment with venv as follows from VS Code integrated terminal:

python3 -m venv <name>

after cd in the directory, I activated it by doing source <name>/bin/activate

How can I make it available for the kernel of my VS Code integration of jupyter notebook? I only see the default python installations as possible kernels i.e. usr/bin/python3

Also, let's say I would like to then revert the process and remove that kernel - how can I do it?

3 Answers 3

6

As mentioned by Molly Wang below, the kernel does not appear in the list of Python environments and you should upvote this issue in Github. As a workaround, you could open the python interpreter menu in VS Code (crtl+p) and type "Python interpreter" and then navigate to your venv python (choose the right version within the /bin folder in your venv)

enter image description here

Sign up to request clarification or add additional context in comments.

3 Comments

It works. The kernel showed up after I added the interpreter in the virtual environment.
It works, but I need to restart vscode after adding interpreter
in vs code settings.json, I fixed by puttiing "python.venvPath": "/home/user/.venv/", so just the venv directory, not the bin directory or python bin file
2

Create a new python environment via the console, then from a notebook try and select it as a kernel it doesn't appear in the list of python environments. This phenomenon also occurs in my VS Code.

There's an issue in github, Python extension team will see if there's enough upvotes, then they will consider this feature request in future planning. You may upvote the issue.

1 Comment

Yes, indeed. Virtual environments created with venv do not automatically get listed under the list of Python interpreters of VS Code. The work around I found is to select interpreter and manually navigate to the "python" from inside the venv folder.
0

My hacky workaround - create a new .ipynb in the same directory, VSC will find the interpreter, then you can go back to your original notebook and select it there.

For whatever reason I'm finding this is happening frequently for me now with Notebooks that used to never have a problem.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.