How to run another Synapse Notebook from one Synapse Notebook

Shao Peng Sun 81 Reputation points
2023-04-14T15:44:46.26+00:00

I try to run another Synapse notebook in one Synapse notebook. And I found the documents for using %run or mssparkutils.notebook.run, but both of them failed. when I use %run, I got the error below, but as you can see that the notebook is there.
User's image

When I use mssparkutils.notebook.run, in the error log it also mentioned the notebook cannot be found. Is there anything I have in the code run? How to specify the path to find the notebook?
User's image

Azure Synapse Analytics
Azure Synapse Analytics
An Azure analytics service that brings together data integration, enterprise data warehousing, and big data analytics. Previously known as Azure SQL Data Warehouse.
4,696 questions
0 comments No comments
{count} votes

Accepted answer
  1. PRADEEPCHEEKATLA-MSFT 85,586 Reputation points Microsoft Employee
    2023-04-17T05:32:57.0166667+00:00


    Shao Peng Sun
    - Thanks for the question and using MS Q&A platform.

    You will experience this issue, in case if you are not published the notebook which you are calling from another notebook.

    As per the repro, I had created a named notebook10 and tried to run from another notebook named notebook11 without publishing the notebooks which returned same error message as shown: User's image

    Then, I tried to publish all the notebooks in my workspace. User's image

    When I tried to call notebook10 from notebook11 which worked as excepted. User's image

    Hope this helps. Do let us know if you any further queries.


2 additional answers

Sort by: Most helpful
  1. Vinodh247 13,801 Reputation points
    2023-04-16T06:30:24.6266667+00:00

    Hi Thanks for reaching out to Microsoft Q&A. By importing libraries like below...

    from notebookutils import mssparkutils mssparkutils.notebook.run('folder/notebook_name')

    For detailed step by step instructions and other available options, go through the below git link. https://dustinvannoy.com/2022/01/20/azure-synapse-spark-external-python-packages/ Please Upvote and Accept as answer if the reply was helpful, this will be helpful to other community members.

    0 comments No comments

  2. Zeeshan Nasir Bajwa 646 Reputation points Student Ambassador
    2023-04-17T06:30:07.86+00:00

    The error you are encountering suggests that the notebook you are trying to run cannot be found. This could be because the notebook path you are specifying is incorrect, or because the notebook is not in the same workspace as the notebook you are running the %run or mssparkutils.notebook.run command from. To specify the correct path to the notebook you want to run, you can use the absolute path to the notebook or a relative path. For example, if the notebook you want to run is located in the same folder as the notebook you are running the %run or mssparkutils.notebook.run command from, you can use a relative path like this:

    shellCopy code
    %run ./my_other_notebook
    

    If the notebook you want to run is located in a different folder, you can use a relative or absolute path to specify the notebook location. For example, if the notebook you want to run is located in a subfolder called subfolder within the same folder as the notebook you are running the %run or mssparkutils.notebook.run command from, you can use a relative path like this:

    shellCopy code
    %run ./subfolder/my_other_notebook
    

    Alternatively, you can use an absolute path to specify the notebook location, like this:

    shellCopy code
    %run /path/to/my_other_notebook
    

    Make sure that the path you are specifying is correct and that the notebook exists in the specified location. Also, check that you have the necessary permissions to access the notebook. If you continue to encounter errors, you can try using the dbutils.notebook.run command instead of mssparkutils.notebook.run. The syntax for using dbutils.notebook.run is similar to mssparkutils.notebook.run, but it might work better for your specific use case.