Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change Default kernel in jupyter notebook

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 ?

like image 261
ankit Avatar asked Jul 03 '20 06:07

ankit


People also ask

How do I set the default kernel in Jupyter Notebook?

Open the notebook. Then navigate to Kernel -> Change Kernel and select the kernel you want to use. The question was specifically for setting the default kernel.

Can you change kernel in Jupyter Notebook?

To change the kernel version in Jupyter Python Notebooks follow the steps below : Open the Python Notebook and click on " Kernel " from the menu bar located on top of the python notebook. Click on " Change kernel " from the drop down box that appears and chose the version that is required.

How do I update my Jupyter Notebook kernel?

Use pip install notebook --upgrade or conda upgrade notebook to upgrade to the latest release. We strongly recommend that you upgrade to version 9+ of pip before upgrading notebook . Use pip install pip --upgrade to upgrade pip. Check pip version with pip --version .

How do I change the default kernel in Vscode?

To change your current active kernel, click on the current kernel to bring up the VS Code kernel selector and select which kernel you want to switch to from the list.


3 Answers

See this answer on GitHub. As explained there:

the default kernel name is rarely used. It really only comes into play when a request is received to start a kernel and the kernel name is not specified in the request payload. Since both Notebook and Lab UIs essentially require the user to select a kernel (for new notebooks), it doesn't really come into play.

Put c.MappingKernelManager.default_kernel_name='newDefault' in config file.

To confirm the default is in place, hit the kernelspecs REST API of your running notebook server (e.g., http://localhost:8888/api/kernelspecs) and you should see the default kernel name as the first entry in the returned payload.

like image 176
Raz Avatar answered Oct 06 '22 19:10

Raz


jupyter notebook --generate-config 

open the generated config file change
change this line to your desired kernel

#c.MultiKernelManager.default_kernel_name = 'python3' 

like

c.MultiKernelManager.default_kernel_name = 'py38' 
like image 32
Reza Farshi Avatar answered Oct 06 '22 19:10

Reza Farshi


Yes this is possible via the .ipynb file itself. Set the following variables in the metadata, specifically the name which identifies the kernel

  "metadata": {
   "kernelspec": {
   "display_name": "Python 3 (PyTorch 1.6 Python 3.6 CPU Optimized)",
   "language": "python",
   "name": "python3__SAGEMAKER_INTERNAL__arn:aws:sagemaker:us-east-1:081325390199:image/pytorch-1.6-cpu-py36-ubuntu16.04-v1"
   },
   "language_info": {
    "codemirror_mode": {

like image 2
Ricky Sahu Avatar answered Oct 06 '22 18:10

Ricky Sahu