<?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: Importing python module in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/importing-python-module/m-p/31864#M23218</link>
    <description>&lt;P&gt;Thanks for the reply. The file I have is part of a repo within the repo structure. Is there a way to import dependencies within a repo. The repo structure looks something like below:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="image"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/1507i623DFA7AA439892A/image-size/large?v=v2&amp;amp;px=999" role="button" title="image" alt="image" /&gt;&lt;/span&gt;And I need to import the some_util module in my_notebook.&lt;/P&gt;</description>
    <pubDate>Wed, 14 Sep 2022 05:00:22 GMT</pubDate>
    <dc:creator>tariq</dc:creator>
    <dc:date>2022-09-14T05:00:22Z</dc:date>
    <item>
      <title>Importing python module</title>
      <link>https://community.databricks.com/t5/data-engineering/importing-python-module/m-p/31860#M23214</link>
      <description>&lt;P&gt;I'm not sure how a simple thing like importing a module in python can be so broken in such a product. First, I was able to make it work using the following:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;import sys
sys.path.append("/Workspace/Repos/Github Repo/sparkling-to-databricks/src")
from utils.some_util import *&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I was able to use the imported function. But then I restarted the cluster and this would not work even though the path is in sys.path.&lt;/P&gt;&lt;P&gt;I also tried the following:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;spark.sparkContext.addPyFile("/Workspace/Repos/Github Repo/my-repo/src/utils/some_util.py")&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This did not work either. Can someone please tell me what I'm doing wrong here and suggest a solution. Thanks.&lt;/P&gt;</description>
      <pubDate>Tue, 13 Sep 2022 14:46:38 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/importing-python-module/m-p/31860#M23214</guid>
      <dc:creator>tariq</dc:creator>
      <dc:date>2022-09-13T14:46:38Z</dc:date>
    </item>
    <item>
      <title>Re: Importing python module</title>
      <link>https://community.databricks.com/t5/data-engineering/importing-python-module/m-p/31861#M23215</link>
      <description>&lt;P&gt;&lt;A href="https://docs.databricks.com/libraries/index.html" target="test_blank"&gt;https://docs.databricks.com/libraries/index.html&lt;/A&gt; the docs should help.  &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Keep in mind that paths on the cluster are distributed paths and that paths in python are local to the driver.  If you do %fs ls / you'll get a different result than if you do %sh fs ls /&lt;/P&gt;</description>
      <pubDate>Tue, 13 Sep 2022 14:58:50 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/importing-python-module/m-p/31861#M23215</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2022-09-13T14:58:50Z</dc:date>
    </item>
    <item>
      <title>Re: Importing python module</title>
      <link>https://community.databricks.com/t5/data-engineering/importing-python-module/m-p/31862#M23216</link>
      <description>&lt;P&gt;So there's no other way than creating a library?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Sep 2022 15:09:36 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/importing-python-module/m-p/31862#M23216</guid>
      <dc:creator>tariq</dc:creator>
      <dc:date>2022-09-13T15:09:36Z</dc:date>
    </item>
    <item>
      <title>Re: Importing python module</title>
      <link>https://community.databricks.com/t5/data-engineering/importing-python-module/m-p/31863#M23217</link>
      <description>&lt;P&gt;I too wonder the same thing. How can importing a python module be so difficult and not even documented lol.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;No need for libraries..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here's what worked for me..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Step1: Upload the module by first opening a notebook &amp;gt;&amp;gt; File &amp;gt;&amp;gt; Upload Data &amp;gt;&amp;gt; drag and drop your module&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Step2: Click on Next&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Step3: Copy the databricks path for your module. (this path is diplayed in the pop up that you see just after click on Next)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For me , if my module is named &lt;B&gt;test_module &lt;/B&gt;the path looks like&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt; &lt;B&gt;&lt;I&gt;&lt;U&gt;dbfs:/FileStore/shared_uploads/krishz@company.com/test_module.py &lt;/U&gt;&lt;/I&gt;&lt;/B&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Step4: Append the above to Path (albeit with changes)&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Change 1: Change &lt;B&gt;&lt;U&gt;dbfs:/&lt;/U&gt; &lt;/B&gt;to &lt;B&gt;/dbfs/ &lt;/B&gt;&lt;/LI&gt;&lt;LI&gt;Change 2: remove your module name from the path &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now my path to append looks like &lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;B&gt;&lt;I&gt;&lt;U&gt;﻿/dbfs/FileStore/shared_uploads/krishz@company.com&lt;/U&gt;&lt;/I&gt;&lt;/B&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Step5: &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;import sys
sys.path.append("/dbfs/FileStore/shared_uploads/krishz@company.com")&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Step6:&lt;/P&gt;&lt;P&gt;Now you can import simply by using below:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;import test_module&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Post this, you may write code as if you had imported test_module in your usual Jupyter notebook - No need to worry about any databricks intricacies. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Lemme know if you are unclear about any step.  Honestly speaking, I don't know why you were recommended to use libraries for such a simple request.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Sep 2022 04:36:54 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/importing-python-module/m-p/31863#M23217</guid>
      <dc:creator>KrishZ</dc:creator>
      <dc:date>2022-09-14T04:36:54Z</dc:date>
    </item>
    <item>
      <title>Re: Importing python module</title>
      <link>https://community.databricks.com/t5/data-engineering/importing-python-module/m-p/31864#M23218</link>
      <description>&lt;P&gt;Thanks for the reply. The file I have is part of a repo within the repo structure. Is there a way to import dependencies within a repo. The repo structure looks something like below:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="image"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/1507i623DFA7AA439892A/image-size/large?v=v2&amp;amp;px=999" role="button" title="image" alt="image" /&gt;&lt;/span&gt;And I need to import the some_util module in my_notebook.&lt;/P&gt;</description>
      <pubDate>Wed, 14 Sep 2022 05:00:22 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/importing-python-module/m-p/31864#M23218</guid>
      <dc:creator>tariq</dc:creator>
      <dc:date>2022-09-14T05:00:22Z</dc:date>
    </item>
  </channel>
</rss>

