โ06-15-2024 11:36 PM - edited โ06-15-2024 11:38 PM
Could you please provide guidance on the correct way to dynamically import a Python module from a user-specific path in Databricks Repos? Any advice on resolving the ModuleNotFoundError would be greatly appreciated.
udf_check_table_exists notebook:
Thank you for your assistance.
โ06-17-2024 09:03 AM
It works for me now ๐ by refer this solution:
[Errno 95] Operation not supported ยท Issue #113823 ยท MicrosoftDocs/azure-docs ยท GitHub
creating a "file" instead of a "notebook" and moving the code from the notebook into the file, I was able to use the "import" statement
my import code:
โ06-16-2024 10:03 PM
Hi,
There are two ways to import functions from other notebook:
โ06-17-2024 01:23 AM
Thanks @Hkesharwani for your replying,
As DLT doesn't support the magic command %run, that's why I'm trying the import function way
my layout like this:
other notebook:
โ06-17-2024 04:28 AM - edited โ06-17-2024 04:29 AM
Hey @tramtran,
I didn't try with repos, but it works with a Workspace path the following way (we're doing it like this so I validated it for you). I guess since Repos are also inside /Workspace, it will work the same way.
Lets use the default /Workspace/Shared folder for this example.
1. Add the .py file with your table_exists function to the /Workspace/Shared folder. Lets call the file function_file.py for this example.
2. Create an __init__.py file in this/Workspace/Shared directory as well. So Databricks knows this is a package index.
3. In the notebook you want to import the function from the .py file, add this:
import sys
sys.path.append("/Workspace/Shared")
then import the function like this:
from function_file import table_exists
Hope this helps, good luck!
โ06-17-2024 05:18 AM
Thanks @jacovangelder,
I did the same as your suggestion, but another error appeared:
OSError: [Errno 95] Operation not supported: '/Workspace/Shared/function_file.py'.
Have you faced this issue before?
โ06-17-2024 05:46 AM
I haven't, have you done exactly the steps outlined? It looks like perhaps you're not allowed to read form the shared location? Not 100% sure.
โ06-17-2024 09:03 AM
It works for me now ๐ by refer this solution:
[Errno 95] Operation not supported ยท Issue #113823 ยท MicrosoftDocs/azure-docs ยท GitHub
creating a "file" instead of a "notebook" and moving the code from the notebook into the file, I was able to use the "import" statement
my import code:
โ06-17-2024 09:07 AM
Thank you all again
Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you wonโt want to miss the chance to attend and share knowledge.
If there isnโt a group near you, start one and help create a community that brings people together.
Request a New Group