<?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 files into another Workspace Python file does not work in Warehousing &amp; Analytics</title>
    <link>https://community.databricks.com/t5/warehousing-analytics/importing-python-files-into-another-workspace-python-file-does/m-p/91212#M1564</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/122091"&gt;@sachamourier&lt;/a&gt;,&lt;BR /&gt;Your snapshot.py is Databricks Notebook, and not a .py file.&lt;BR /&gt;&lt;BR /&gt;Check the icons.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="filipniziol_0-1726845391181.png" style="width: 400px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/11383i1E66C168E9B7C953/image-size/medium?v=v2&amp;amp;px=400" role="button" title="filipniziol_0-1726845391181.png" alt="filipniziol_0-1726845391181.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Try adding snapshot.py as a file. It will work:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="filipniziol_1-1726845462675.png" style="width: 400px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/11384i07FD6C4CD248AE0B/image-size/medium?v=v2&amp;amp;px=400" role="button" title="filipniziol_1-1726845462675.png" alt="filipniziol_1-1726845462675.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Also, after you replace snapshot notebook with snapshot file, make sure to clear state in the notebook that you use to reference the snapshot.py:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="filipniziol_0-1726845646839.png" style="width: 400px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/11385i2CF125F6F19CCE86/image-size/medium?v=v2&amp;amp;px=400" role="button" title="filipniziol_0-1726845646839.png" alt="filipniziol_0-1726845646839.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;</description>
    <pubDate>Fri, 20 Sep 2024 15:20:56 GMT</pubDate>
    <dc:creator>filipniziol</dc:creator>
    <dc:date>2024-09-20T15:20:56Z</dc:date>
    <item>
      <title>Importing Python files into another Workspace Python file does not work</title>
      <link>https://community.databricks.com/t5/warehousing-analytics/importing-python-files-into-another-workspace-python-file-does/m-p/91201#M1561</link>
      <description>&lt;P&gt;I have created Python modules containing some Python functions and I would like to import them from a notebook contained in the Workspace.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;For example, I have a "etl" directory, containing a "snapshot.py" file with some Python functions, and an empty "__init__.py" file as well. When working inside my repo in Databricks, the "from etl.snapshot import *" Python command works with no issue and I am able to call my functions. However, when running that same command from the Workspace, I get a "Module not found" error. I have tried to use the "sys.path.append()" approach as suggested in many forums or in multiple YouTube videos but this still does not work.&lt;BR /&gt;&lt;BR /&gt;I am looking for a solution, as I would like to avoid using the %run command.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Thanks a lot in advance for your help,&lt;BR /&gt;Sacha&lt;/P&gt;</description>
      <pubDate>Fri, 20 Sep 2024 14:27:58 GMT</pubDate>
      <guid>https://community.databricks.com/t5/warehousing-analytics/importing-python-files-into-another-workspace-python-file-does/m-p/91201#M1561</guid>
      <dc:creator>sachamourier</dc:creator>
      <dc:date>2024-09-20T14:27:58Z</dc:date>
    </item>
    <item>
      <title>Re: Importing Python files into another Workspace Python file does not work</title>
      <link>https://community.databricks.com/t5/warehousing-analytics/importing-python-files-into-another-workspace-python-file-does/m-p/91203#M1562</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/122091"&gt;@sachamourier&lt;/a&gt;&amp;nbsp;,&lt;BR /&gt;It will work, but you need carefully craft path to sys.path.append(), you even do not need __init__.py to make it work.&lt;BR /&gt;Try to hard-code the path to the snapshot.py in workspace.&lt;BR /&gt;&lt;BR /&gt;Add this to your notebook:&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN&gt;&lt;SPAN class=""&gt;import&lt;/SPAN&gt; &lt;SPAN class=""&gt;sys&lt;/SPAN&gt;&lt;/SPAN&gt;
&lt;SPAN&gt;&lt;SPAN class=""&gt;import&lt;/SPAN&gt; &lt;SPAN class=""&gt;os&lt;/SPAN&gt;&lt;/SPAN&gt;

&lt;SPAN&gt;&lt;SPAN class=""&gt;absolute_directory_path&lt;/SPAN&gt; &lt;SPAN class=""&gt;=&lt;/SPAN&gt; &lt;SPAN class=""&gt;os&lt;/SPAN&gt;&lt;SPAN class=""&gt;.&lt;/SPAN&gt;&lt;SPAN class=""&gt;path&lt;/SPAN&gt;&lt;SPAN class=""&gt;.&lt;/SPAN&gt;&lt;SPAN class=""&gt;normpath&lt;/SPAN&gt;&lt;SPAN class=""&gt;(&lt;/SPAN&gt;&lt;SPAN class=""&gt;"&lt;/SPAN&gt;&lt;SPAN class=""&gt;/Workspace/&amp;lt;path to directory where the snapshot.py file is located&amp;gt;&lt;/SPAN&gt;&lt;SPAN class=""&gt;"&lt;/SPAN&gt;&lt;SPAN class=""&gt;)&lt;/SPAN&gt;&lt;/SPAN&gt;

&lt;SPAN&gt;&lt;SPAN class=""&gt;if&lt;/SPAN&gt; &lt;SPAN class=""&gt;absolute_directory_path&lt;/SPAN&gt; &lt;SPAN class=""&gt;not&lt;/SPAN&gt; &lt;SPAN class=""&gt;in&lt;/SPAN&gt; &lt;SPAN class=""&gt;sys&lt;/SPAN&gt;&lt;SPAN class=""&gt;.&lt;/SPAN&gt;&lt;SPAN class=""&gt;path&lt;/SPAN&gt;&lt;SPAN class=""&gt;:&lt;/SPAN&gt;&lt;/SPAN&gt;
&lt;SPAN&gt;    &lt;SPAN class=""&gt;sys&lt;/SPAN&gt;&lt;SPAN class=""&gt;.&lt;/SPAN&gt;&lt;SPAN class=""&gt;path&lt;/SPAN&gt;&lt;SPAN class=""&gt;.&lt;/SPAN&gt;&lt;SPAN class=""&gt;append&lt;/SPAN&gt;&lt;SPAN class=""&gt;(&lt;/SPAN&gt;&lt;SPAN class=""&gt;absolute_directory_path&lt;/SPAN&gt;&lt;SPAN class=""&gt;)&lt;/SPAN&gt;&lt;/SPAN&gt;
&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;And then you make your import:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import snapshot&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Sep 2024 14:45:45 GMT</pubDate>
      <guid>https://community.databricks.com/t5/warehousing-analytics/importing-python-files-into-another-workspace-python-file-does/m-p/91203#M1562</guid>
      <dc:creator>filipniziol</dc:creator>
      <dc:date>2024-09-20T14:45:45Z</dc:date>
    </item>
    <item>
      <title>Re: Importing Python files into another Workspace Python file does not work</title>
      <link>https://community.databricks.com/t5/warehousing-analytics/importing-python-files-into-another-workspace-python-file-does/m-p/91208#M1563</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/117376"&gt;@filipniziol&lt;/a&gt;&amp;nbsp;,&lt;BR /&gt;Thank you for your response. I have tried but this still does not work. The path gets added to "sys.path" though. You can find attached images of the issue.&lt;BR /&gt;Sacha&lt;BR /&gt;&lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2024-09-20 165613.png" style="width: 700px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/11381i79A4A61226EF1CA4/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot 2024-09-20 165613.png" alt="Screenshot 2024-09-20 165613.png" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2024-09-20 165645.png" style="width: 334px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/11382iEEDC9F43B5836E7D/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot 2024-09-20 165645.png" alt="Screenshot 2024-09-20 165645.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Sep 2024 14:58:45 GMT</pubDate>
      <guid>https://community.databricks.com/t5/warehousing-analytics/importing-python-files-into-another-workspace-python-file-does/m-p/91208#M1563</guid>
      <dc:creator>sachamourier</dc:creator>
      <dc:date>2024-09-20T14:58:45Z</dc:date>
    </item>
    <item>
      <title>Re: Importing Python files into another Workspace Python file does not work</title>
      <link>https://community.databricks.com/t5/warehousing-analytics/importing-python-files-into-another-workspace-python-file-does/m-p/91212#M1564</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/122091"&gt;@sachamourier&lt;/a&gt;,&lt;BR /&gt;Your snapshot.py is Databricks Notebook, and not a .py file.&lt;BR /&gt;&lt;BR /&gt;Check the icons.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="filipniziol_0-1726845391181.png" style="width: 400px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/11383i1E66C168E9B7C953/image-size/medium?v=v2&amp;amp;px=400" role="button" title="filipniziol_0-1726845391181.png" alt="filipniziol_0-1726845391181.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Try adding snapshot.py as a file. It will work:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="filipniziol_1-1726845462675.png" style="width: 400px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/11384i07FD6C4CD248AE0B/image-size/medium?v=v2&amp;amp;px=400" role="button" title="filipniziol_1-1726845462675.png" alt="filipniziol_1-1726845462675.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Also, after you replace snapshot notebook with snapshot file, make sure to clear state in the notebook that you use to reference the snapshot.py:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="filipniziol_0-1726845646839.png" style="width: 400px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/11385i2CF125F6F19CCE86/image-size/medium?v=v2&amp;amp;px=400" role="button" title="filipniziol_0-1726845646839.png" alt="filipniziol_0-1726845646839.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;</description>
      <pubDate>Fri, 20 Sep 2024 15:20:56 GMT</pubDate>
      <guid>https://community.databricks.com/t5/warehousing-analytics/importing-python-files-into-another-workspace-python-file-does/m-p/91212#M1564</guid>
      <dc:creator>filipniziol</dc:creator>
      <dc:date>2024-09-20T15:20:56Z</dc:date>
    </item>
  </channel>
</rss>

