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.

How to Change Default kernel in jupyter notebook

See original GitHub issue

I am using ipython 6.4.0 on ubuntu 20.04 and using jupyter kernelspec list , I found, there are 2 kernels :

  1. practice_applied_ai
  2. python3

When I open any .ipynb file, it directly opens in “python3” but I want to open it in “practice_applied_ai” because I created virtual environment practice_applied_ai and only in this kernel I can import Tensorflow 2.2.0 for my work.
My question is, Is there any way to change my default kernel without removing any kernel ?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8

github_iconTop GitHub Comments

1reaction
ankitgupta1729commented, Jul 5, 2020

Sir, Thank you so much for the help 😃

If you’re opening existing notebook files, the kernel-name is part of the file’s metadata - so it will use that kernel.

Yes, I checked now. I thought I can open other files which are used with different kernels in the kernel “practice_applied_ai”. I did not know that kernel name is part of file’s metadata. Now, I understood it.

1reaction
kevin-batescommented, Jul 5, 2020

Sounds like you’re doing the right thing.

when I open any file from that, it opens it in python3 kernel

If you’re opening existing notebook files, the kernel-name is part of the file’s metadata - so it will use that kernel. I’m not sure how to trigger the use of the “default kernel” other than from the REST API I described previously. The Notebook and Lab UIs require the user to select a kernel when creating notebooks and that selection is from the list of available kernels - which includes the default kernel (among others). You might have the wrong idea about when the default kernel name is used.

Another way to determine your configuration of a default kernel is working is to visit this URL via a web browser: http://localhost:8888/api/kernelspecs. This is much easier than issuing a POST request as I described previously.

The response to visiting that URL is the set of kernelspec information. The first portion of which is the name of the default kernel. Again, you’ll see here the the ‘ir’ kernel is (now) configured as my default:

{
  "default": "ir",
  "kernelspecs": {
    "python3": {
      "name": "python3",
      "spec": {
        "argv": [
          "/opt/anaconda3/envs/elyra-dev/bin/python",
          "-m",
          "ipykernel_launcher",
          "-f",
          "{connection_file}"
        ],
        "env": {},
        "display_name": "Python 3",
        "language": "python",
        "interrupt_mode": "signal",
        "metadata": {}
      },
      "resources": {
        "logo-64x64": "/kernelspecs/python3/logo-64x64.png",
        "logo-32x32": "/kernelspecs/python3/logo-32x32.png"
      }
    },
    "ir": {
      "name": "ir",
      "spec": {
        "argv": [
          "/Library/Frameworks/R.framework/Resources/bin/R",
          "--slave",
          "-e",
          "IRkernel::main()",
          "--args",
          "{connection_file}"
        ],
        "env": {},
        "display_name": "R",
        "language": "R",
        "interrupt_mode": "signal",
        "metadata": {}
      },
      "resources": {
        "kernel.js": "/kernelspecs/ir/kernel.js",
        "logo-64x64": "/kernelspecs/ir/logo-64x64.png"
      }
    }
  }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Change Default kernel in jupyter notebook - Stack Overflow
Not sure how to change the default kernel, but you can change the kernel being used in a notebook, after opening the notebook,...
Read more >
How to change the kernel version in Jupyter Python Notebooks?
Open the Python Notebook and click on " Kernel " from the menu bar located on top of the python notebook. · Click...
Read more >
Jupyter Kernel Selection — CoCalc Manual documentation
To select the kernel in a CoCalc Jupyter notebook, click the “Kernel” button (usually in the middle toolbar, depending on your configuration). In...
Read more >
Jupyter Notebook Kernels: How to Add, Change, Remove
Add, remove and change Kernels to use with Jupyter notebook.
Read more >
Change default kernel of jupyter notebook not working #3338
To confirm the default is in place, hit the kernelspecs REST API of your running notebook server (e.g., http://localhost:8888/api/kernelspecs) ...
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