I am working with jupyter notebook using google colab(all the files are in the drive). I have 2 files: Exploratory_Data_Analysis.ipynb et PCA.ipynb. I want to import to use the data comming from first one in the secon one. using only the jupyter notebook locally(not with google colaboratory), the importing is working simply by doing this:
!pip install import-ipynb
import import_ipynb
import Exploratory_Data_Analysis as eda
But with google colab I tried the following:
!pip install import-ipynb
import import_ipynb
!pip install -U -q PyDrive
from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
from google.colab import auth
from oauth2client.client import GoogleCredentials
import os
import pandas as pd
auth.authenticate_user()
gauth = GoogleAuth()
gauth.credentials = GoogleCredentials.get_application_default()
drive = GoogleDrive(gauth)
listed = drive.ListFile({'q': "'1CXqv7-PZmYrWes4MOk' in
parents and trashed=false"}).GetList()
for file in listed:
print('title {}, id {}'.format(file['title'], file['id']))
eda = os.path.join(download_path, 'Exploratory_Data_Analysis.ipynb')
temp_eda = drive.CreateFile({'id': '1YpDhXGeJVtzuxUJS5gKsUbm'})
temp_eda.GetContentFile(eda)
import Exploratory_Data_Analysis
and getting this:
importing Jupyter notebook from Exploratory_Data_Analysis.ipynb
NotJSONError: Notebook does not appear to be JSON: ''...
are there any other ways to import its own ipynb files on google colab?
Have you managed to import your notebook/ipynb file to a Google Colab project?
The way I migrate my ongoing work in local jupyter-notebook to Google Colab is by using Github and Clouderizer. This method also allows me work on jupyter notebook environment that as if I do it locally but able to sync my work to Google Colab instantly. In addition, this method allows me to import modules .ipynb/.py to my ongoing notebook that I'm working on by simply do something like import <my own python/ipynb module>
. I would recommend this setup instead of using hairy linux command line on Google Colab.
Here is the tutorial how to easily setup your notebook from github to Google Colab using Clouderizer: Medium tutorial.
Basically, these are the steps you need to setup your ipynb notebook as well as the dataset folder using Clouderizer:
Below code worked perfectly for me. 1. Copy all ipynb files into one folder in colab 2. Share the ipynb file from colab, see link: https://www.pingshiuanchua.com/blog/post/importing-your-own-python-module-or-python-file-in-colaboratory 3. Then follow the below steps:
!pip install import-ipynb
import import_ipynb
# Install the PyDrive wrapper & import libraries.
# This only needs to be done once per notebook.
!pip install -U -q PyDrive
from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
from google.colab import auth
from oauth2client.client import GoogleCredentials
# Authenticate and create the PyDrive client.
# This only needs to be done once per notebook.
auth.authenticate_user()
gauth = GoogleAuth()
gauth.credentials = GoogleCredentials.get_application_default()
drive = GoogleDrive(gauth)
# Copy the link and remove the front part of the link (i.e. https://drive.google.com/open?id=) to get the file ID.
your_module = drive.CreateFile({'id':'eyetgd1zyxwvutsrqponmlkjihgfedcba'})
your_module.GetContentFile('myfile.ipynb')
import myfile
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