I have a problem with import ipynb file from my google drive. I've tried solutions from: Importing .py files in Google Colab How to import custom modules in google colab?
but does not work for me.
# COLAB
from google.colab import files
from google.colab import drive
# SYS
import sys
# IPYNB
!pip install import-ipynb
import import_ipynb
# UTIL
import importlib.util
I've tried something like this:
drive.mount('/content/drive')
sys.path.append('/content/drive/My Drive/Colab Notebooks/')
import Data_Preparation_Library
Or this:
!cp "/content/drive/My Drive/Colab Notebooks/Data_Preparation_Library.ipynb"
import Data_Preparation_Library
Here is how my gdrive structure looks like:
Thank You for answers in advance
You can import files module from google. colab . Then call upload() to launch a “File Upload” dialog and select the file(s) you wish to upload. Once the upload is complete, your file(s) should appear in “Files explorer” and you can read the file as you would normally.
Since a Colab notebook is hosted on Google's cloud servers, there's no direct access to files on your local drive (unlike a notebook hosted on your machine) or any other environment by default. However, Colab provides various options to connect to almost any data source you can imagine.
The simplest way to share files is to mount your Google Drive. It will ask you to visit a link to ALLOW "Google Files Stream" to access your drive. After that a long alphanumeric auth code will be shown that needs to be entered in your Colab's notebook.
SOURCE
Step 1 Primarily, you must Mount your google drive in google colab: Code to below, your files on your google drive is import files/packages inside a google colab.
# Mount your google drive in google colab
from google.colab import drive
drive.mount('/content/drive')
Step 2 Secondly, insert the directory to your python path using sys:
# Insert the directory
import sys
sys.path.insert(0,’/content/drive/My Drive/ColabNotebooks’)
Step 3 Now, you can be able to import your module or file stuff from that directory.
# Import your module or file
import my_module
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With