Is there a way to set the default kernel in JupyterLab in Azure ML notebooks, in prepare_only mode? I know it's only a few clicks away to change it on the top right - but I need to do this many times a day, and I often forget. Having the right default would be very convenient.
I saw this solution: Change Default kernel in jupyter notebook which suggest to add a line like
c.MultiKernelManager.default_kernel_name = 'py38'
in the Jupyter config.
For JupyterLab in Azure ML, I can edit the Jupyter config file with:
sudo nano /home/azureuser/.jupyter/jupyter_notebook_config.py
But this has no effect. Update: /home/azureuser/.jupyter/jupyter_notebook_config.py and /home/azureuser/.jupyter/jupyter_server_config.py gets overwritten anyway every time I restart Jupyterlab or restart my compute...
We create those notebooks using papermill, so I tried to set the kernel explicitly like this:
papermill.execute_notebook(
... ,
prepare_only=True,
kernel_name='py38'
)
But that had no effect either, when using prepare_only mode.
How can I set the kernel then? Any idea how else the default kernel could be set in prepare_only mode?
To set default kernel in Jupyter in Azure ML Studio, Follow the steps below:-
I created a new kernel with name py38 using the code below:-
py38 kernel got created successfully like below:-
I created one jupyter_notebook_config.py by navigating to .jupyter directory, and typed this code. If you do not have jupyter directory in your Azure ML studio you can create a new one :-
Code 1 :-
Code 2:-
I got permission denied error while creating the jupyter_notebook_config.py file with the code above like below:-
Error:-
In order to resolve this error, I ran the command below:-
Output:- jupyter_notebook_config.py file got created with "c.KernelManager.default_kernel_name = 'py38'" config like below:-
Output of Code 2:-
Now, I set the Kernel to py38 and when I restarted the cluster or connected to jupyter notebook py38 was selected by default and did not change everytime, I wanted to connect to my Azure ML notebook. Refer below:-
py38 got selected by default after restart and whenever I wanted to connect to Jupyter notebook.
You can manually set the kernel in the notebook information as you are using Papermill in prepare only mode. You can accomplish this by including the following metadata in the notebook:
The command shown below can be used to add this metadata to the notebook:
Additionally, Papermill's prepare only mode only gets the notebook ready for execution, not actually runs it. As a result, using kernel name in execute notebook with prepare only=True will have no effect when manually setting the kernel.