'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 :
- practice_applied_ai
- 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 ?
Solution 1:[1]
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.
Solution 2:[2]
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'
Solution 3:[3]
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": {
Solution 4:[4]
Not sure how to change the default kernel, but you can change the kernel being used in a notebook, after opening the notebook, as explained in this site.
Open the notebook. Then navigate to Kernel -> Change Kernel and select the kernel you want to use.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Raz |
Solution 2 | Reza Farshi |
Solution 3 | Ricky Sahu |
Solution 4 | Atul Balaji |