Showing posts with label notebook. Show all posts
Showing posts with label notebook. Show all posts

Friday

Convert Google Colab notebook into local jupyter notebook

 

unplash

You can convert a Colab notebook into a local Jupyter notebook by following these steps:

  1. Open the Colab notebook in a web browser.
  2. Click the File menu and select Download.
  3. In the Save As dialog box, select Jupyter Notebook (.ipynb) as the file type and click Save.
  4. The Jupyter notebook will be downloaded to your computer.
  5. Open the Jupyter notebook in a Jupyter notebook viewer.

You can also use the following command to convert a Colab notebook into a local Jupyter notebook:

jupyter nbconvert --to notebook <path-to-colab-notebook

For example, to convert a Colab notebook named my_notebook.ipynb to a local Jupyter notebook, you would use the following command:

jupyter nbconvert --to notebook my_notebook.ipynb

Once you have converted a Colab notebook into a local Jupyter notebook, you can run it locally on your computer.

I think your datasets are in Google Drive. It is easier to connet and work a google driver folder from Google Colab. However how will you do from your local jupter notebook!

There are a few ways to connect the dataset are in Google Drive from local Jupyter notebook.

One way is to use the Google Drive API. To do this, you will need to create a Google Cloud Platform project and enable the Google Drive API. Once you have done that, you can use the following code to mount your Google Drive to your Jupyter notebook:

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

Once your Google Drive is mounted, you can access your datasets by using the /content/drive/My Drive path.

Another way to connect your Google Drive to your Jupyter notebook is to use the Google Drive File Stream application. To do this, you will need to download and install the Google Drive File Stream application. Once you have done that, you can mount your Google Drive to your Jupyter notebook by following these steps:

  1. Open the Google Drive File Stream application.
  2. Click the Menu button and select Connect.
  3. In the Connect to Google Drive dialog box, select the My Computer option and click Next.
  4. In the Select Folders dialog box, select the folders that you want to mount and click Next.
  5. In the Choose a Drive Letter dialog box, select a drive letter for your Google Drive and click Finish.

Once your Google Drive is mounted, you can access your datasets by using the drive letter that you selected.

Finally, you can also connect your Google Drive to your Jupyter notebook by using the Google Drive API and the Google Drive SDK. To do this, you will need to create a Google Cloud Platform project and enable the Google Drive API. Once you have done that, you can install the Google Drive SDK using the following command:

pip install google-drive-sdk

Once you have installed the Google Drive SDK, you can use the following code to mount your Google Drive to your Jupyter notebook:

from google.drive import GoogleDriv


drive = GoogleDrive()


# Create a file token.json file in the current directory.
drive.CreateFileToken()


# Mount your Google Drive to the current directory.
drive.Mount('My Drive')

Once your Google Drive is mounted, you can access your datasets by using the My Drive path.

Thank you.