2 weeks ago - last edited 2 weeks ago
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.
a week ago
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:
a week ago
Hi,
There are two ways to import functions from other notebook:
a week ago
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:
a week ago - last edited a week ago
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!
a week ago
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?
a week ago
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.
a week ago
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:
a week ago
Thank you all again
Excited to expand your horizons with us? Click here to Register and begin your journey to success!
Already a member? Login and join your local regional user group! If there isn’t one near you, fill out this form and we’ll create one for you to join!