1 Answer
- Newest
- Most votes
- Most comments
0
In order to import custom modules in JupyterLab on Amazon SageMaker. Firstly make sure that you have similar directory Structure:
root_folder/ │ ├── n.ipynb │ └── shared/ ├── __init__.py └── wr.py
Here are a few approaches you can try to import your custom module:
1)Modify the Python path: At the beginning of your notebook, add the following code:
import sys sys.path.append('/home/sagemaker-user')
This adds the root directory of your SageMaker environment to the Python path. After this, you should be able to import your module using:
from shared.wr import fns
- Alternatively ,add the following code to n.ipynb
import sys # Add current directory to path import os current_dir = os.getcwd() if current_dir not in sys.path: sys.path.append(current_dir) # Import module from shared.wr import fns
Relevant content
- asked 2 years ago
- AWS OFFICIALUpdated 3 years ago
I am using Glue