<?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: code execution from Databrick folder in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/code-execution-from-databrick-folder/m-p/95127#M39042</link>
    <description>&lt;P&gt;Hi Kartik,&lt;/P&gt;&lt;P&gt;Can you elaborate further on your query? I may not able to understand you properly but if your source code is checked out to databricks repos and you want to execute your code for testing purposes , had you try setting up your repo dir into sys paths?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;this can go into the top cell of your execution notebook before you're doing your imports.&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;import&lt;/SPAN&gt;&lt;SPAN&gt; os, sys&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;# get current directory&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;path &lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt; os.&lt;/SPAN&gt;&lt;SPAN&gt;getcwd&lt;/SPAN&gt;&lt;SPAN&gt;()&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;print&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;"Current Directory"&lt;/SPAN&gt;&lt;SPAN&gt;, path)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;# prints parent directory&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;repo_dir &lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt; os.path.&lt;/SPAN&gt;&lt;SPAN&gt;abspath&lt;/SPAN&gt;&lt;SPAN&gt;(os.path.&lt;/SPAN&gt;&lt;SPAN&gt;join&lt;/SPAN&gt;&lt;SPAN&gt;(path, os.pardir))&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;# repo_dir = os.path.dirname(os.pardir())&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;sys.path.&lt;/SPAN&gt;&lt;SPAN&gt;append&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;f&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN&gt;{&lt;/SPAN&gt;&lt;SPAN&gt;repo_dir&lt;/SPAN&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;SPAN&gt;/"&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;print&lt;/SPAN&gt;&lt;SPAN&gt;(repo_dir)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
    <pubDate>Mon, 21 Oct 2024 07:56:32 GMT</pubDate>
    <dc:creator>saurabh18cs</dc:creator>
    <dc:date>2024-10-21T07:56:32Z</dc:date>
    <item>
      <title>code execution from Databrick folder</title>
      <link>https://community.databricks.com/t5/data-engineering/code-execution-from-databrick-folder/m-p/95125#M39040</link>
      <description>&lt;P&gt;We are able to run a notebook that references Python code using import statements from a Databricks repo&lt;BR /&gt;with the source code checked out. However, we encounter a ModuleNotFoundError when executing the same code from a folder.&lt;/P&gt;&lt;P&gt;Error: ModuleNotFoundError: No module named ...&lt;/P&gt;&lt;P&gt;Is there a future roadmap to enable code execution from Databricks folder and subfolders?&lt;/P&gt;</description>
      <pubDate>Mon, 21 Oct 2024 07:33:59 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/code-execution-from-databrick-folder/m-p/95125#M39040</guid>
      <dc:creator>Kartikb</dc:creator>
      <dc:date>2024-10-21T07:33:59Z</dc:date>
    </item>
    <item>
      <title>Re: code execution from Databrick folder</title>
      <link>https://community.databricks.com/t5/data-engineering/code-execution-from-databrick-folder/m-p/95127#M39042</link>
      <description>&lt;P&gt;Hi Kartik,&lt;/P&gt;&lt;P&gt;Can you elaborate further on your query? I may not able to understand you properly but if your source code is checked out to databricks repos and you want to execute your code for testing purposes , had you try setting up your repo dir into sys paths?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;this can go into the top cell of your execution notebook before you're doing your imports.&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;import&lt;/SPAN&gt;&lt;SPAN&gt; os, sys&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;# get current directory&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;path &lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt; os.&lt;/SPAN&gt;&lt;SPAN&gt;getcwd&lt;/SPAN&gt;&lt;SPAN&gt;()&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;print&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;"Current Directory"&lt;/SPAN&gt;&lt;SPAN&gt;, path)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;# prints parent directory&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;repo_dir &lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt; os.path.&lt;/SPAN&gt;&lt;SPAN&gt;abspath&lt;/SPAN&gt;&lt;SPAN&gt;(os.path.&lt;/SPAN&gt;&lt;SPAN&gt;join&lt;/SPAN&gt;&lt;SPAN&gt;(path, os.pardir))&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;# repo_dir = os.path.dirname(os.pardir())&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;sys.path.&lt;/SPAN&gt;&lt;SPAN&gt;append&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;f&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN&gt;{&lt;/SPAN&gt;&lt;SPAN&gt;repo_dir&lt;/SPAN&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;SPAN&gt;/"&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;print&lt;/SPAN&gt;&lt;SPAN&gt;(repo_dir)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Mon, 21 Oct 2024 07:56:32 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/code-execution-from-databrick-folder/m-p/95127#M39042</guid>
      <dc:creator>saurabh18cs</dc:creator>
      <dc:date>2024-10-21T07:56:32Z</dc:date>
    </item>
    <item>
      <title>Re: code execution from Databrick folder</title>
      <link>https://community.databricks.com/t5/data-engineering/code-execution-from-databrick-folder/m-p/95198#M39053</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/56939"&gt;@Kartikb&lt;/a&gt;&amp;nbsp;,&lt;BR /&gt;&lt;BR /&gt;This feature is already available.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;As&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/22314"&gt;@saurabh18cs&lt;/a&gt;&amp;nbsp; mentioned, you probably have not added the location of your python code to sys.path.&lt;BR /&gt;&lt;BR /&gt;Also, it is important to note, that your python code must be&lt;STRONG&gt; a file&lt;/STRONG&gt;, and not a notebook. You can recognize by checking the object icon or object type:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="filipniziol_0-1729505797970.png" style="width: 400px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/12108iA0D7E898A41F53E2/image-size/medium?v=v2&amp;amp;px=400" role="button" title="filipniziol_0-1729505797970.png" alt="filipniziol_0-1729505797970.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="filipniziol_1-1729505930222.png" style="width: 400px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/12109i088DA4D6CF2F1BF8/image-size/medium?v=v2&amp;amp;px=400" role="button" title="filipniziol_1-1729505930222.png" alt="filipniziol_1-1729505930222.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 21 Oct 2024 10:20:14 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/code-execution-from-databrick-folder/m-p/95198#M39053</guid>
      <dc:creator>filipniziol</dc:creator>
      <dc:date>2024-10-21T10:20:14Z</dc:date>
    </item>
    <item>
      <title>Re: code execution from Databrick folder</title>
      <link>https://community.databricks.com/t5/data-engineering/code-execution-from-databrick-folder/m-p/95227#M39058</link>
      <description>&lt;P&gt;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/56939"&gt;@Kartikb&lt;/a&gt;&amp;nbsp;Best approach is by creating a package and Install Code as a Module or Wheel. This ensures your code is accessible across notebooks and distributed jobs without manual path adjustments​&lt;/P&gt;</description>
      <pubDate>Mon, 21 Oct 2024 11:42:44 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/code-execution-from-databrick-folder/m-p/95227#M39058</guid>
      <dc:creator>Panda</dc:creator>
      <dc:date>2024-10-21T11:42:44Z</dc:date>
    </item>
    <item>
      <title>Re: code execution from Databrick folder</title>
      <link>https://community.databricks.com/t5/data-engineering/code-execution-from-databrick-folder/m-p/95242#M39063</link>
      <description>&lt;DIV&gt;Below worked as you have suggested.&lt;/DIV&gt;&lt;DIV&gt;import os, sys&lt;/DIV&gt;&lt;DIV&gt;project_path = os.path.abspath("/Workspace/&amp;lt;folder-name-1&amp;gt;/&amp;lt;folder-name-2&amp;gt;/&amp;lt;top-level-code-folder&amp;gt;")&lt;/DIV&gt;&lt;DIV&gt;if project_path not in sys.path:&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; sys.path.append(project_path)&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Mon, 21 Oct 2024 12:21:50 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/code-execution-from-databrick-folder/m-p/95242#M39063</guid>
      <dc:creator>Kartikb</dc:creator>
      <dc:date>2024-10-21T12:21:50Z</dc:date>
    </item>
  </channel>
</rss>

