JeremyFord
New Contributor III

Hi @RobinK I've been struggling with the same. I've experimented with the following and it looks like it does what you want. 

1. Create a new Notebook (set_notebook_paths.py) just for setting the paths as above using the "bundle_root" method. My actual notebooks are two levels deep from the root hence the "../..".

 

# Databricks notebook source

import sys
import os

try:
    root = dbutils.widgets.get("bundle_root")
    if root:
        print("bundle_root: " + root)
    else:
        root = os.path.abspath('../..')
except:
    print("bundle_root not defined. Using relative path.")
    root = os.path.abspath('../..')

sys.path.append(root)
print(sys.path)

 

2. Use the MAGIC %run in your main notebook to run that notebook.  That magically makes it work when running as a Job, but is ignored for local development.

 

# Databricks notebook source

# MAGIC %run ../set_notebook_paths

# COMMAND ----------

from lib.blah import some_function

 

It not as nice as the "Files in Repo's" that just works without all this path manipulation 😞

Hope that helps, and if you find a better way please let me know!