1. Mount your google drive in google colab

from google.colab import drive
drive.mount('/content/gdrive/')

2. Append the directory to your python path

For example, if you want to import a .py file called mymodule.py in your google drive, which is saved in "/content/drive/MyDrive/example_folder", you need to add the path of the directory which saves mymodule.py to system path.

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

['/content/drive/MyDrive/example_folder',
 '',
 '/content',
 '/env/python',
 '/usr/lib/python37.zip',
 '/usr/lib/python3.7',
 '/usr/lib/python3.7/lib-dynload',
 '/usr/local/lib/python3.7/dist-packages',
 '/usr/lib/python3/dist-packages',
 '/usr/local/lib/python3.7/dist-packages/IPython/extensions',
 '/root/.ipython']




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()
Nice to meet you!