cancel
Showing results for 
Search instead for 
Did you mean: 
Administration & Architecture
Explore discussions on Databricks administration, deployment strategies, and architectural best practices. Connect with administrators and architects to optimize your Databricks environment for performance, scalability, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 

%run command gives error on free edition

JonnyData
New Contributor III

Hi,

I'm testing out running one Notebook from another using the %run magic command in the Databricks Free Edition. Just really simple test stuff but get the following error:

Failed to parse %run command: string matching regex '\$[\w_]+' expected but 'p' found. If notebook path contains spaces, wrap with double quotes.

The path doesn't contain spaces and wrapping in double quotes doesn't help, either.

Any suggestions?

1 ACCEPTED SOLUTION

Accepted Solutions

Advika
Databricks Employee
Databricks Employee

@JonnyData, it's considered best practice to put %run in a cell by itself. If you include other code (like print(book_publisher)) in the same cell, it may execute before the %run command has finished loading everything.

You can try either of the following approaches:

  • Split the code across two cells: Use the %run command in one cell and place the print statement in another.
  • Run selected text: Run only the %run command by selecting it, then execute the print statement.

https://docs.databricks.com/aws/en/notebooks/notebook-workflows#use-run-to-import-a-notebook

View solution in original post

4 REPLIES 4

Advika
Databricks Employee
Databricks Employee

Hello @JonnyData!

This parsing error typically appears when the notebook path isn't in the expected format. Could you share the exact %run command you're using?
Also, please ensure the path is a workspace path, either absolute (starting with /) or relative (like ./NotebookName, and both notebooks must be in the same folder).

JonnyData
New Contributor III

Hi Advika - thanks for this.

In my Workspace I've first created a folder called HolusTest

In there I have 2 Notebooks HolusTest1 which containes the lines:

%run ./HolusTestSetup
print(book_publisher)

and HolusTestSetup, which contains one line

book_publisher = "OReilly"

The language 'default' for both is python and the code's from Databricks Certified Data Engineer Associate Study Guide which I'm just working through to give myself a better all round grounding in Databricks.

Thanks in advance for any help

Advika
Databricks Employee
Databricks Employee

@JonnyData, it's considered best practice to put %run in a cell by itself. If you include other code (like print(book_publisher)) in the same cell, it may execute before the %run command has finished loading everything.

You can try either of the following approaches:

  • Split the code across two cells: Use the %run command in one cell and place the print statement in another.
  • Run selected text: Run only the %run command by selecting it, then execute the print statement.

https://docs.databricks.com/aws/en/notebooks/notebook-workflows#use-run-to-import-a-notebook

JonnyData
New Contributor III

Hi Advika,

Thanks for that - it worked a treat!

Cheers

John