11

I have created a simple jupyter notebook in VS Code and selected it to use my default python3 kernel (/usr/local/bin/python3). Everything works great.

Then, I close VS Code and re-open the notebook, it asks me to select the kernel every time.

Is there a way to default the kernel of this notebook to my python3 interpreter?

In case it helps, when I view the notebook json, it has the following in it:

        "kernelspec": {
        "name": "python3",
        "display_name": "Python 3.9.6 64-bit"
1
  • It looks like VS Code saves this information on the Workspace level. If I open a workspace and save it, then later the kernel selection is preserved. Is there a way to preserve it on the notebook level? Commented Aug 22, 2021 at 19:49

3 Answers 3

4

It's not available for now, but they think it is a reasonable request, and considering it. You can refer to this page.

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

Comments

4

Two ways

one:

You can go into the command Juptyer: Filter Kernels

use command to filter out kernals, all kernals follow alphanumeric order. So, u can tick a few https://github.com/microsoft/vscode-jupyter/discussions/10130

two:

ps. Can try, but might not work after a while? idk why, but it works once.

Enforce choices to only 1, then reload vscode windows

"jupyter.kernels.filter": [
      {
        "path": "/bin/python3"
      }
    ]

Meanwhile you can visually browser all the paths on ur local Click the text button at the top right corner. <Python 3.x****>

It pops up like below

how to pick path ?

3 Comments

I'm afraid it's not a sufficient condition for python kernel auto-detection (at it fails for new, unseen notebooks).
What it can achieve though, is to reduce the number of choices on the drop-down list after you manually click on the Select kernel button. So it deserves half a point I suppose (rounded up:)
One interesting side-effect of narrowing python kernels choice to just one (which requires filtering all choice except one) is that python files (*.py) debugger (from the "Debug Python Files" menu) now has no choice other than the correct one, so it works out-of-the box, without additional hacking required.
2

This option is available in the VS Code settings:

Open settings, search interpreter and you should get the option to set an option to set Python: Default Interpreter Path

Add the path to the default Python kernel you want to use and Jupyter Labs should always use this specified kernel moving forward.

Default Interpreter Setting

2 Comments

I'm afraid it's not a sufficient condition for python kernel auto-detection (at it fails for new, unseen notebooks).
yep, doesn't work for me. It helps with .py files, but nothing appears in available jupyter kernels

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.