How to automatically mount my Google Drive to Google Colab

I have recently discovered Google Colab and I am wondering if there is an option to permanently authorize Google Colab to access and mount my Google Drive.

from google.colab import drive
drive.mount('/content/drive')
Go to this URL in a browser: https://accounts.google.com/o/oauth2/auth?client_id=xxx
Enter your authorization code:
··········
Mounted at /content/drive

Right now, I need to all the time insert manually the authorization code and I want when I start a new Google Colab to have my drive mounted.

Is there an option to do that or I should execute this all the time manually?

Topic colab google

Category Data Science


  1. Choose the folder icon in the left sidebar.
  2. Wait for the runtime to initialize (you will see icons appear under the word "Files" in the sidebar).
  3. Choose the Google Drive icon (the hover text is "Mount Drive").

Using this method, rather than messing up your notebook with the google.colab package, is nice and Colab maintains the authorization until you "Unmount Drive" using the crossed out Google Drive icon.


I was working on a google colab project, after a while I decided to copy the work and rename it as a new version (manual type of git control). After doing this I noticed that my google drive doesn't automatically mount. After checking some of the settings I went to File > Update Drive Preview after doing this, the google drive is automatically added when restarting the notebook. Even when commenting out these lines...

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

Hope this helps


For some reason, Colab allows me to automatically mount if I'm the creator of the notebook. If that's not the case, such was when I create a copy, the from google.colab import drive code block automatically gets added, and I have to authorize again.

File > New notebook

Then navigate to the file browser. Click on "Mount Drive".

From then on, every time I connect, it automatically mounts Drive during the Initializing phase.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.