Chad Goldsworthy
Chad Goldsworthy

Reputation: 79

Papermill Azure Function App: "No such kernel named python3" when executing a notebook

I am trying to develop an Azure function app that executes jupyter notebooks stored in blob storage through papermill. It's all working up until the point of papermill.execute_notebook(...) where I then get the following error:

File "/home/site/wwwroot/.python_packages/lib/site-packages/jupyter_client/kernelspec.py", line 287, in get_kernel_spec
    raise NoSuchKernel(kernel_name)
jupyter_client.kernelspec.NoSuchKernel: No such kernel named python3

For testing purposes, I am doing a very simple notebook that just accepts two parameters ["name", "age"] and inserts them into a sql table. My code below (written in python 3.8) is simply passing a name and age into the papermill.execute_notebook(<notebook_path>). I have tested that notebook and it works fine. It's just when I try and run it through papermill, I get the error "No such kernel named python3".

    blob_service_client = BlobServiceClient.from_connection_string(connection_string)
            
    with tempfile.NamedTemporaryFile(delete=False, suffix=".ipynb") as temp_notebook:
        blob_client = blob_service_client.get_blob_client(container=container, blob=blob_path)
        temp_notebook.write(blob_client.download_blob().readall())
        input_notebook_path = temp_notebook.name
    
    output_notebook_path = '/tmp/output_notebook.ipynb'
            
    papermill.execute_notebook(
        input_path=input_notebook_path,
        output_path=output_notebook_path,
        parameters=dict(name='Prince', age='99')
    )

Any advice would be much appreciated.

Upvotes: 0

Views: 761

Answers (1)

SiddheshDesai
SiddheshDesai

Reputation: 8195

I received the same error code as yours like below:-

enter image description here

In order to resolve this error make sure you have the kernel installed in your terminal where you are running your function like below:-

pip install ipykernel
python -m ipykernel install --user --name jupytersiddhesh

enter image description here

After installing the kernel I specified the kernel name in my init.py file and the Function executed successfully, Like below:-

import logging
import tempfile
import azure.functions as func
from azure.storage.blob import BlobServiceClient
import papermill as pm

def main(req: func.HttpRequest) -> func.HttpResponse:
    logging.info('Python HTTP trigger function processed a request.')

    # Get the connection string and blob information from the request
    connection_string = 'DefaultEndpointsProtocol=https;AccountName=valleystrg32;AccountKey=xxxxxxxxxxxxxxxxxxtDj78nA==;EndpointSuffix=core.windows.net'
    container_name = 'data'
    blob_name = 'notebook.ipynb'
    # local_file_path = tempfile.mktemp(suffix=".py")
    # output_file_path = tempfile.mktemp(suffix=".ipynb")
    local_file_path = r'C:\Users\xxxx\Desktop\pythonnotebook\notebook.ipynb'  # Double backslashes
    output_file_path = r'C:\Users\xxxx\Desktop\pythonnotebook\notebook.ipynb'  # Double backslashes

    # Create a BlobServiceClient object
    blob_service_client = BlobServiceClient.from_connection_string(connection_string)

    # Create a BlobClient object to download the notebook
    blob_client = blob_service_client.get_blob_client(container=container_name, blob=blob_name)

    # Download the notebook to a local file
    with open(local_file_path, "wb") as my_blob:
        download_stream = blob_client.download_blob()
        my_blob.write(download_stream.readall())
    # Specify the kernel name when executing the notebook
    kernel_name = "jupytersiddhesh"  # You need to replace this with the actual kernel name
    pm.execute_notebook(local_file_path, output_file_path, kernel_name=kernel_name)
    # Execute the notebook using papermill
    pm.execute_notebook(local_file_path, output_file_path)

    return func.HttpResponse(f"Notebook executed successfully.")

enter image description here

Upvotes: 0

Related Questions