<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to set Python rootpath when deploying with DABs in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/how-to-set-python-rootpath-when-deploying-with-dabs/m-p/52306#M29427</link>
    <description>&lt;P&gt;&lt;SPAN&gt;Hello Robin,&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;You’ll have to either use wheel files to package your libs and use those (see docs &lt;A href="https://docs.databricks.com/en/dev-tools/bundles/python-wheel.html" target="_self"&gt;here&lt;/A&gt;), to make imports work out of the box. Otherwise, your entry point file needs to add the bundle root directory (or whatever the lib directory is) to your&amp;nbsp;&lt;CODE class="" data-stringify-type="code"&gt;sys.path.&lt;/CODE&gt;&amp;nbsp;This can be achieved by adding a parameter&amp;nbsp;and then process that parameter in the first couple of lines of your entry point file (as defined in the bundle).&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;For example, if your bundle task looks like so:&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;- task_key: stream&lt;BR /&gt;  notebook_task:&lt;BR /&gt;    notebook_path: /path/to/file.ipynb&lt;BR /&gt;    &lt;STRONG&gt;base_parameters:&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;      bundle_root: &lt;/STRONG&gt;&lt;SPAN&gt;&lt;STRONG&gt;${workspace.file_path}&lt;/STRONG&gt;&lt;BR /&gt;  job_cluster_key: Job_cluster&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P&gt;note that "bundle_root" is arbitrary, it can be whatever you want it to be called. ${workspace.file_path} will substitute this value at runtime so it will work in different workspaces seemlessly.&lt;/P&gt;
&lt;P&gt;Now in your /path/to/file.ipynb file, you would do something like:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;SPAN class=""&gt;root = dbutils&lt;SPAN class=""&gt;.&lt;SPAN class=""&gt;widgets&lt;SPAN class=""&gt;.&lt;SPAN class=""&gt;get&lt;SPAN class=""&gt;(&lt;SPAN class=""&gt;"bundle_root"&lt;SPAN class=""&gt;)&lt;BR /&gt;sys.path.append(root)&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Hope this helps!&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;A href="https://docs.databricks.com/en/dev-tools/bundles/python-wheel.html" target="_blank" rel="noopener"&gt;&lt;CODE class="" data-stringify-type="code"&gt;&lt;/CODE&gt;&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 16 Nov 2023 14:37:23 GMT</pubDate>
    <dc:creator>Corbin</dc:creator>
    <dc:date>2023-11-16T14:37:23Z</dc:date>
    <item>
      <title>How to set Python rootpath when deploying with DABs</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-set-python-rootpath-when-deploying-with-dabs/m-p/50634#M28852</link>
      <description>&lt;P&gt;We have structured our code according to the documentation (&lt;A title="notebooks-best-practices" href="https://docs.databricks.com/en/notebooks/best-practices.html#step-3-move-code-into-a-shared-module" target="_blank" rel="noopener"&gt;notebooks-best-practices&lt;/A&gt;). We use Jupyter notebooks and have outsourced logic to Python modules. Unfortunately, the example described in the documentation only works if you have checked out the code as a repository in Databricks, because only in this case is the Python rootpath set correctly (output of the "sys.path" Python variable contains the path to the repository root). However, since we are now deploying our code with Databricks Asset Bundles, it is not checked out as a repository in Databricks, but ends up in the workspace. Apparently, only the path of the current folder is set there (the output of the "sys.path" Python variable only contains the path to the current folder). As a result, it is not possible to load modules that are in other folders.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Folder structure&lt;/STRONG&gt;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;- my_project
-- notebooks
--- my_notebook.ipynb
-- my_modules
--- my_module.py&lt;/LI-CODE&gt;&lt;P&gt;In the notebook I want to import functions of my module:&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;PRE&gt;&lt;SPAN class=""&gt;from&lt;/SPAN&gt; my_modules&lt;SPAN class=""&gt;.&lt;/SPAN&gt;my_module &lt;SPAN class=""&gt;import&lt;/SPAN&gt; &lt;SPAN class=""&gt;*&lt;/SPAN&gt;&lt;/PRE&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&lt;SPAN&gt;But an error occurs:&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;PRE&gt;ModuleNotFoundError&lt;/PRE&gt;&lt;P&gt;Output of&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN class=""&gt;import&lt;/SPAN&gt; sys
sys&lt;SPAN class=""&gt;.&lt;/SPAN&gt;path&lt;/PRE&gt;&lt;P&gt;When I check out the example code from the docs (it contains the current folder path and the path of the root folder):&lt;/P&gt;&lt;PRE&gt;&lt;SPAN class=""&gt;[&lt;/SPAN&gt;&lt;SPAN class=""&gt;'/databricks/python_shell/scripts'&lt;/SPAN&gt;&lt;SPAN class=""&gt;,&lt;/SPAN&gt;
 &lt;SPAN class=""&gt;'/local_disk0/spark-64d2e6e2-e358-49fb-ad1b-c95f90915d9e/userFiles-7afa9a58-9505-40ec-94e9-a073787631d8'&lt;/SPAN&gt;&lt;SPAN class=""&gt;,&lt;/SPAN&gt;
 &lt;SPAN class=""&gt;'/databricks/spark/python'&lt;/SPAN&gt;&lt;SPAN class=""&gt;,&lt;/SPAN&gt;
 &lt;SPAN class=""&gt;'/databricks/spark/python/lib/py4j-0.10.9.7-src.zip'&lt;/SPAN&gt;&lt;SPAN class=""&gt;,&lt;/SPAN&gt;
 &lt;SPAN class=""&gt;'/databricks/jars/spark--driver--driver-spark_3.5_2.12_deploy.jar'&lt;/SPAN&gt;&lt;SPAN class=""&gt;,&lt;/SPAN&gt;
 &lt;SPAN class=""&gt;'/Workspace/Repos/&amp;lt;username&amp;gt;/notebook-best-practices/notebooks'&lt;/SPAN&gt;&lt;SPAN class=""&gt;,&lt;/SPAN&gt;
 &lt;SPAN class=""&gt;'/Workspace/Repos/&amp;lt;username&amp;gt;/notebook-best-practices'&lt;/SPAN&gt;&lt;SPAN class=""&gt;,&lt;/SPAN&gt;
 &lt;SPAN class=""&gt;'/databricks/python_shell'&lt;/SPAN&gt;&lt;SPAN class=""&gt;,&lt;/SPAN&gt;
 &lt;SPAN class=""&gt;'/usr/lib/python310.zip'&lt;/SPAN&gt;&lt;SPAN class=""&gt;,&lt;/SPAN&gt;
 &lt;SPAN class=""&gt;'/usr/lib/python3.10'&lt;/SPAN&gt;&lt;SPAN class=""&gt;,&lt;/SPAN&gt;
 &lt;SPAN class=""&gt;'/usr/lib/python3.10/lib-dynload'&lt;/SPAN&gt;&lt;SPAN class=""&gt;,&lt;/SPAN&gt;
 &lt;SPAN class=""&gt;''&lt;/SPAN&gt;&lt;SPAN class=""&gt;,&lt;/SPAN&gt;
 &lt;SPAN class=""&gt;'/local_disk0/.ephemeral_nfs/envs/pythonEnv-1f4b77f0-6bd3-4d36-a1cc-693215915cd6/lib/python3.10/site-packages'&lt;/SPAN&gt;&lt;SPAN class=""&gt;,&lt;/SPAN&gt;
 &lt;SPAN class=""&gt;'/local_disk0/.ephemeral_nfs/cluster_libraries/python/lib/python3.10/site-packages'&lt;/SPAN&gt;&lt;SPAN class=""&gt;,&lt;/SPAN&gt;
 &lt;SPAN class=""&gt;'/databricks/python/lib/python3.10/site-packages'&lt;/SPAN&gt;&lt;SPAN class=""&gt;,&lt;/SPAN&gt;
 &lt;SPAN class=""&gt;'/usr/local/lib/python3.10/dist-packages'&lt;/SPAN&gt;&lt;SPAN class=""&gt;,&lt;/SPAN&gt;
 &lt;SPAN class=""&gt;'/usr/lib/python3/dist-packages'&lt;/SPAN&gt;&lt;SPAN class=""&gt;]&lt;/SPAN&gt;
&lt;/PRE&gt;&lt;P&gt;Of my own code (it only contains the path of the current folder, but not the root path):&lt;/P&gt;&lt;PRE&gt;&lt;SPAN class=""&gt;[&lt;/SPAN&gt;&lt;SPAN class=""&gt;'/databricks/python_shell/scripts'&lt;/SPAN&gt;&lt;SPAN class=""&gt;,&lt;/SPAN&gt;
 &lt;SPAN class=""&gt;'/local_disk0/spark-64d2e6e2-e358-49fb-ad1b-c95f90915d9e/userFiles-7afa9a58-9505-40ec-94e9-a073787631d8'&lt;/SPAN&gt;&lt;SPAN class=""&gt;,&lt;/SPAN&gt;
 &lt;SPAN class=""&gt;'/databricks/spark/python'&lt;/SPAN&gt;&lt;SPAN class=""&gt;,&lt;/SPAN&gt;
 &lt;SPAN class=""&gt;'/databricks/spark/python/lib/py4j-0.10.9.7-src.zip'&lt;/SPAN&gt;&lt;SPAN class=""&gt;,&lt;/SPAN&gt;
 &lt;SPAN class=""&gt;'/databricks/jars/spark--driver--driver-spark_3.5_2.12_deploy.jar'&lt;/SPAN&gt;&lt;SPAN class=""&gt;,&lt;/SPAN&gt;
 &lt;SPAN class=""&gt;'/databricks/python_shell'&lt;/SPAN&gt;&lt;SPAN class=""&gt;,&lt;/SPAN&gt;
 &lt;SPAN class=""&gt;'/usr/lib/python310.zip'&lt;/SPAN&gt;&lt;SPAN class=""&gt;,&lt;/SPAN&gt;
 &lt;SPAN class=""&gt;'/usr/lib/python3.10'&lt;/SPAN&gt;&lt;SPAN class=""&gt;,&lt;/SPAN&gt;
 &lt;SPAN class=""&gt;'/usr/lib/python3.10/lib-dynload'&lt;/SPAN&gt;&lt;SPAN class=""&gt;,&lt;/SPAN&gt;
 &lt;SPAN class=""&gt;'/local_disk0/.ephemeral_nfs/envs/pythonEnv-c070c35e-ee85-452e-a03e-fe117d43a515/lib/python3.10/site-packages'&lt;/SPAN&gt;&lt;SPAN class=""&gt;,&lt;/SPAN&gt;
 &lt;SPAN class=""&gt;'/local_disk0/.ephemeral_nfs/cluster_libraries/python/lib/python3.10/site-packages'&lt;/SPAN&gt;&lt;SPAN class=""&gt;,&lt;/SPAN&gt;
 &lt;SPAN class=""&gt;'/databricks/python/lib/python3.10/site-packages'&lt;/SPAN&gt;&lt;SPAN class=""&gt;,&lt;/SPAN&gt;
 &lt;SPAN class=""&gt;'/usr/local/lib/python3.10/dist-packages'&lt;/SPAN&gt;&lt;SPAN class=""&gt;,&lt;/SPAN&gt;
 &lt;SPAN class=""&gt;'/usr/lib/python3/dist-packages'&lt;/SPAN&gt;&lt;SPAN class=""&gt;,&lt;/SPAN&gt;
 &lt;SPAN class=""&gt;''&lt;/SPAN&gt;&lt;SPAN class=""&gt;,&lt;/SPAN&gt;
 &lt;SPAN class=""&gt;'/Workspace/Users/&amp;lt;username&amp;gt;/modular_test/notebooks'&lt;/SPAN&gt;&lt;SPAN class=""&gt;]&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;How do I set the root path of my code, when deploying it with Databricks Asset Bundles?&lt;/P&gt;&lt;P&gt;Is there a better way, then manipulating the sys.path variable? This code works, but we have to copy it in each notebook that imports modules.&lt;/P&gt;&lt;PRE&gt;notebook_path &lt;SPAN class=""&gt;=&lt;/SPAN&gt; dbutils&lt;SPAN class=""&gt;.&lt;/SPAN&gt;notebook&lt;SPAN class=""&gt;.&lt;/SPAN&gt;entry_point&lt;SPAN class=""&gt;.&lt;/SPAN&gt;getDbutils&lt;SPAN class=""&gt;(&lt;/SPAN&gt;&lt;SPAN class=""&gt;)&lt;/SPAN&gt;&lt;SPAN class=""&gt;.&lt;/SPAN&gt;notebook&lt;SPAN class=""&gt;(&lt;/SPAN&gt;&lt;SPAN class=""&gt;)&lt;/SPAN&gt;&lt;SPAN class=""&gt;.&lt;/SPAN&gt;getContext&lt;SPAN class=""&gt;(&lt;/SPAN&gt;&lt;SPAN class=""&gt;)&lt;/SPAN&gt;&lt;SPAN class=""&gt;.&lt;/SPAN&gt;notebookPath&lt;SPAN class=""&gt;(&lt;/SPAN&gt;&lt;SPAN class=""&gt;)&lt;/SPAN&gt;&lt;SPAN class=""&gt;.&lt;/SPAN&gt;get&lt;SPAN class=""&gt;(&lt;/SPAN&gt;&lt;SPAN class=""&gt;)&lt;/SPAN&gt;
sys&lt;SPAN class=""&gt;.&lt;/SPAN&gt;path&lt;SPAN class=""&gt;.&lt;/SPAN&gt;append&lt;SPAN class=""&gt;(&lt;/SPAN&gt;&lt;SPAN class=""&gt;"/Workspace"&lt;/SPAN&gt; &lt;SPAN class=""&gt;+&lt;/SPAN&gt; os&lt;SPAN class=""&gt;.&lt;/SPAN&gt;path&lt;SPAN class=""&gt;.&lt;/SPAN&gt;dirname&lt;SPAN class=""&gt;(&lt;/SPAN&gt;os&lt;SPAN class=""&gt;.&lt;/SPAN&gt;path&lt;SPAN class=""&gt;.&lt;/SPAN&gt;dirname&lt;SPAN class=""&gt;(&lt;/SPAN&gt;os&lt;SPAN class=""&gt;.&lt;/SPAN&gt;path&lt;SPAN class=""&gt;.&lt;/SPAN&gt;dirname&lt;SPAN class=""&gt;(&lt;/SPAN&gt;notebook_path&lt;SPAN class=""&gt;)&lt;/SPAN&gt;&lt;SPAN class=""&gt;)&lt;/SPAN&gt;&lt;SPAN class=""&gt;)&lt;/SPAN&gt;&lt;SPAN class=""&gt;)&lt;/SPAN&gt;&lt;/PRE&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Wed, 08 Nov 2023 12:17:52 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-set-python-rootpath-when-deploying-with-dabs/m-p/50634#M28852</guid>
      <dc:creator>RobinK</dc:creator>
      <dc:date>2023-11-08T12:17:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to set Python rootpath when deploying with DABs</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-set-python-rootpath-when-deploying-with-dabs/m-p/52275#M29425</link>
      <description>&lt;P&gt;Hi &lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/66027"&gt;@RobinK&lt;/a&gt;, I asked a similar question over here: &lt;A href="https://community.databricks.com/t5/warehousing-analytics/import-python-files-as-modules-in-workspace/m-p/52274/highlight/true#M1051" target="_blank" rel="noopener"&gt;https://community.databricks.com/t5/warehousing-analytics/import-python-files-as-modules-in-workspace/m-p/52274/highlight/true#M1051&lt;/A&gt;. I found this resource that gives some good examples of how to import .py modules from outside of your current working directory: &lt;A href="https://github.com/databricks-academy/cli-demo/blob/published/notebooks/00_refactoring_to_relative_import.py" target="_blank" rel="noopener"&gt;https://github.com/databricks-academy/cli-demo/blob/published/notebooks/00_refactoring_to_relative_import.py&lt;/A&gt;. It involves appending your root directory from which you want to import to sys.path. This feels a little hacky (and something I think you typically want to avoid in normal Python development), but it does seem to be the recommended approach. This is basically what Databricks is doing for you when you are working within a Repo.&lt;/P&gt;</description>
      <pubDate>Thu, 16 Nov 2023 13:36:31 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-set-python-rootpath-when-deploying-with-dabs/m-p/52275#M29425</guid>
      <dc:creator>TimReddick</dc:creator>
      <dc:date>2023-11-16T13:36:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to set Python rootpath when deploying with DABs</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-set-python-rootpath-when-deploying-with-dabs/m-p/52306#M29427</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Hello Robin,&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;You’ll have to either use wheel files to package your libs and use those (see docs &lt;A href="https://docs.databricks.com/en/dev-tools/bundles/python-wheel.html" target="_self"&gt;here&lt;/A&gt;), to make imports work out of the box. Otherwise, your entry point file needs to add the bundle root directory (or whatever the lib directory is) to your&amp;nbsp;&lt;CODE class="" data-stringify-type="code"&gt;sys.path.&lt;/CODE&gt;&amp;nbsp;This can be achieved by adding a parameter&amp;nbsp;and then process that parameter in the first couple of lines of your entry point file (as defined in the bundle).&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;For example, if your bundle task looks like so:&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;- task_key: stream&lt;BR /&gt;  notebook_task:&lt;BR /&gt;    notebook_path: /path/to/file.ipynb&lt;BR /&gt;    &lt;STRONG&gt;base_parameters:&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;      bundle_root: &lt;/STRONG&gt;&lt;SPAN&gt;&lt;STRONG&gt;${workspace.file_path}&lt;/STRONG&gt;&lt;BR /&gt;  job_cluster_key: Job_cluster&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P&gt;note that "bundle_root" is arbitrary, it can be whatever you want it to be called. ${workspace.file_path} will substitute this value at runtime so it will work in different workspaces seemlessly.&lt;/P&gt;
&lt;P&gt;Now in your /path/to/file.ipynb file, you would do something like:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;SPAN class=""&gt;root = dbutils&lt;SPAN class=""&gt;.&lt;SPAN class=""&gt;widgets&lt;SPAN class=""&gt;.&lt;SPAN class=""&gt;get&lt;SPAN class=""&gt;(&lt;SPAN class=""&gt;"bundle_root"&lt;SPAN class=""&gt;)&lt;BR /&gt;sys.path.append(root)&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Hope this helps!&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;A href="https://docs.databricks.com/en/dev-tools/bundles/python-wheel.html" target="_blank" rel="noopener"&gt;&lt;CODE class="" data-stringify-type="code"&gt;&lt;/CODE&gt;&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Nov 2023 14:37:23 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-set-python-rootpath-when-deploying-with-dabs/m-p/52306#M29427</guid>
      <dc:creator>Corbin</dc:creator>
      <dc:date>2023-11-16T14:37:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to set Python rootpath when deploying with DABs</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-set-python-rootpath-when-deploying-with-dabs/m-p/53299#M29770</link>
      <description>&lt;P&gt;Hi Corbin,&lt;/P&gt;&lt;P&gt;thank you for the reply. We can work with your solution, but we still have to copy the same code for reading the parameters and it only works for deploying the code with DABs. For local development or debugging in the deployed DABs Code in Databricks we would need to add another workaround, because the parameters (for example "bundle_root") are only set within the job.&lt;/P&gt;&lt;P&gt;Are there any plans to include a parameter "bundle_root" to DABs, that will be set in the "sys.path" variable like in Databricks repos?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Nov 2023 13:45:07 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-set-python-rootpath-when-deploying-with-dabs/m-p/53299#M29770</guid>
      <dc:creator>RobinK</dc:creator>
      <dc:date>2023-11-21T13:45:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to set Python rootpath when deploying with DABs</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-set-python-rootpath-when-deploying-with-dabs/m-p/53549#M29812</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/66027"&gt;@RobinK&lt;/a&gt;&amp;nbsp;I've been struggling with the same. I've experimented with the following and it looks like it does what you want.&amp;nbsp;&lt;/P&gt;&lt;P&gt;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 "../..".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# 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)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2. Use the MAGIC %run in your main notebook to run that notebook.&amp;nbsp; That magically makes it work when running as a Job, but is ignored for local development.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# Databricks notebook source

# MAGIC %run ../set_notebook_paths

# COMMAND ----------

from lib.blah import some_function&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It not as nice as the "Files in Repo's" that just works without all this path manipulation &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Hope that helps, and if you find a better way please let me know!&lt;/P&gt;</description>
      <pubDate>Thu, 23 Nov 2023 02:58:58 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-set-python-rootpath-when-deploying-with-dabs/m-p/53549#M29812</guid>
      <dc:creator>JeremyFord</dc:creator>
      <dc:date>2023-11-23T02:58:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to set Python rootpath when deploying with DABs</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-set-python-rootpath-when-deploying-with-dabs/m-p/55192#M30263</link>
      <description>&lt;P&gt;Thanks! I had to set bundle_root as /Workspace${workspace.file_path} to get my import to work properly. Is this expected?&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="TimReddick_0-1702471131116.png" style="width: 400px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/5588iF953EAD136CA1398/image-size/medium/is-moderation-mode/true?v=v2&amp;amp;px=400" role="button" title="TimReddick_0-1702471131116.png" alt="TimReddick_0-1702471131116.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Dec 2023 12:40:20 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-set-python-rootpath-when-deploying-with-dabs/m-p/55192#M30263</guid>
      <dc:creator>TimReddick</dc:creator>
      <dc:date>2023-12-13T12:40:20Z</dc:date>
    </item>
  </channel>
</rss>

