<?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 Import python files as modules in workspace in Warehousing &amp; Analytics</title>
    <link>https://community.databricks.com/t5/warehousing-analytics/import-python-files-as-modules-in-workspace/m-p/40731#M857</link>
    <description>&lt;P&gt;I'm deploying a new workspace for testing the deployed notebooks. But when trying to import the python files as module in the newly deployed workspace, I'm getting an error saying "&lt;STRONG&gt;function not found&lt;/STRONG&gt;".&lt;/P&gt;&lt;P&gt;Two points to note here:&lt;/P&gt;&lt;P&gt;1. If I append absolute path of the python file to the sys path, it runs fine. But when I append relative path, it throws "not found" error (Relative path is not able to pick workspace's path correctly)&lt;/P&gt;&lt;P&gt;2. If the python file and the notebook are in a same directory, it works fine&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;I know I can use files in repos to fix this but is it possible to do this using workspace only ?&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;NOTE:&lt;/P&gt;&lt;P&gt;In the deployed workspace ,The cwd of the file i want to import is in this format :&amp;nbsp;&lt;SPAN&gt;/home/spark-&lt;FONT color="#000000"&gt;9851f...-....-....-....-.. (not aligned with the folder structure)&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;FONT color="#000000"&gt;But when working with repos, the cwd is correct and is aligned with the folder structure&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 21 Aug 2023 06:50:51 GMT</pubDate>
    <dc:creator>Avin_Kohale</dc:creator>
    <dc:date>2023-08-21T06:50:51Z</dc:date>
    <item>
      <title>Import python files as modules in workspace</title>
      <link>https://community.databricks.com/t5/warehousing-analytics/import-python-files-as-modules-in-workspace/m-p/40731#M857</link>
      <description>&lt;P&gt;I'm deploying a new workspace for testing the deployed notebooks. But when trying to import the python files as module in the newly deployed workspace, I'm getting an error saying "&lt;STRONG&gt;function not found&lt;/STRONG&gt;".&lt;/P&gt;&lt;P&gt;Two points to note here:&lt;/P&gt;&lt;P&gt;1. If I append absolute path of the python file to the sys path, it runs fine. But when I append relative path, it throws "not found" error (Relative path is not able to pick workspace's path correctly)&lt;/P&gt;&lt;P&gt;2. If the python file and the notebook are in a same directory, it works fine&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;I know I can use files in repos to fix this but is it possible to do this using workspace only ?&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;NOTE:&lt;/P&gt;&lt;P&gt;In the deployed workspace ,The cwd of the file i want to import is in this format :&amp;nbsp;&lt;SPAN&gt;/home/spark-&lt;FONT color="#000000"&gt;9851f...-....-....-....-.. (not aligned with the folder structure)&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;FONT color="#000000"&gt;But when working with repos, the cwd is correct and is aligned with the folder structure&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 21 Aug 2023 06:50:51 GMT</pubDate>
      <guid>https://community.databricks.com/t5/warehousing-analytics/import-python-files-as-modules-in-workspace/m-p/40731#M857</guid>
      <dc:creator>Avin_Kohale</dc:creator>
      <dc:date>2023-08-21T06:50:51Z</dc:date>
    </item>
    <item>
      <title>Re: Import python files as modules in workspace</title>
      <link>https://community.databricks.com/t5/warehousing-analytics/import-python-files-as-modules-in-workspace/m-p/46611#M977</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/9"&gt;@Retired_mod&lt;/a&gt;,&amp;nbsp;I see your suggestion to append the necessary path to the sys.path. I'm curious if this is the recommendation for projects deployed via Databricks Asset Bundles. I want to maintain a project structure that looks something like this:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;project/
├── app/
│   ├── nb1.py
│   ├── nb2.py
└── src/
    ├── foo.py
    └── bar.py&lt;/LI-CODE&gt;&lt;P&gt;I want do the following import in nb1:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;from src.foo import foo_func&lt;/LI-CODE&gt;&lt;P&gt;If this were a Databricks Repo, that would work fine since I think Databricks repos add the root to sys.path. However, I'm deploying via Databricks Asset Bundles, which deploy to a workspace directory, not a repo. I'm curious if there are any better recommendations for Databricks Asset Bundles deployments, e.g. could it be deployed directly to a repo?&lt;/P&gt;</description>
      <pubDate>Thu, 28 Sep 2023 16:06:57 GMT</pubDate>
      <guid>https://community.databricks.com/t5/warehousing-analytics/import-python-files-as-modules-in-workspace/m-p/46611#M977</guid>
      <dc:creator>TimReddick</dc:creator>
      <dc:date>2023-09-28T16:06:57Z</dc:date>
    </item>
    <item>
      <title>Re: Import python files as modules in workspace</title>
      <link>https://community.databricks.com/t5/warehousing-analytics/import-python-files-as-modules-in-workspace/m-p/52153#M1050</link>
      <description>&lt;P&gt;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/93517"&gt;@TimW&lt;/a&gt;&amp;nbsp;did you ever solve this? I haven't found a successful way to achieve the same as you've depicted (which we can easily do when using Repos.&lt;/P&gt;</description>
      <pubDate>Thu, 16 Nov 2023 04:59:56 GMT</pubDate>
      <guid>https://community.databricks.com/t5/warehousing-analytics/import-python-files-as-modules-in-workspace/m-p/52153#M1050</guid>
      <dc:creator>JeremyFord</dc:creator>
      <dc:date>2023-11-16T04:59:56Z</dc:date>
    </item>
    <item>
      <title>Re: Import python files as modules in workspace</title>
      <link>https://community.databricks.com/t5/warehousing-analytics/import-python-files-as-modules-in-workspace/m-p/52274#M1051</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/31102"&gt;@JeremyFord&lt;/a&gt;, after some research I think that in my example appending the 'project' directory to sys.path is in fact the recommended way to do this. In studying for the Data Engineering Professional Exam, I came across this resource, which gives some pretty clear examples on how Databricks recommends importing .py modules from outside of your current working directory:&amp;nbsp;&lt;A href="https://github.com/databricks-academy/cli-demo/blob/published/notebooks/00_refactoring_to_relative_import.py" target="_blank"&gt;https://github.com/databricks-academy/cli-demo/blob/published/notebooks/00_refactoring_to_relative_import.py&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Thu, 16 Nov 2023 13:25:06 GMT</pubDate>
      <guid>https://community.databricks.com/t5/warehousing-analytics/import-python-files-as-modules-in-workspace/m-p/52274#M1051</guid>
      <dc:creator>TimReddick</dc:creator>
      <dc:date>2023-11-16T13:25:06Z</dc:date>
    </item>
    <item>
      <title>Re: Import python files as modules in workspace</title>
      <link>https://community.databricks.com/t5/warehousing-analytics/import-python-files-as-modules-in-workspace/m-p/52679#M1054</link>
      <description>&lt;P&gt;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/31102"&gt;@JeremyFord&lt;/a&gt;,&amp;nbsp;I found this &lt;A href="https://community.databricks.com/t5/data-engineering/how-to-set-python-rootpath-when-deploying-with-dabs/m-p/52306/highlight/true#M29427" target="_self"&gt;recommendation&lt;/A&gt;&amp;nbsp;that is probably the best way to handle this. They suggest passing the path of your bundle root as a param to your notebook and then appending to sys.path. I haven't tried it myself, but looks like a good approach.&lt;/P&gt;</description>
      <pubDate>Fri, 17 Nov 2023 10:58:05 GMT</pubDate>
      <guid>https://community.databricks.com/t5/warehousing-analytics/import-python-files-as-modules-in-workspace/m-p/52679#M1054</guid>
      <dc:creator>TimReddick</dc:creator>
      <dc:date>2023-11-17T10:58:05Z</dc:date>
    </item>
  </channel>
</rss>

