How to import custom modules (.py files) from google drive in google colab
from google.colab import drive
drive.mount('/content/gdrive/')
from pathlib import Path
# the path of the directory which saves your .py file
src_dir = Path('/content/drive/MyDrive/example_folder/')
# add the path to system path
import sys
try:
sys.path.index(str(src_dir))
except ValueError:
sys.path.insert(0,str(src_dir))
# print system path
sys.path
After you follow the above steps, you should see /content/drive/MyDrive/example_folder
in sys.path
.
Now, try to import your custom module:
from mymodule import welcome
welcome()