Mounting Google Drive in Google Colab with 3 mouse clicks

Mitesh Parmar
3 min readMar 26, 2021
www.thinglink.com

This article follows on from my previous one; Accessing Google Drive and creating your first Python script in Google Colab — A complete beginners walkthrough: https://miteshparmar1.medium.com/accessing-google-drive-and-creating-your-first-python-script-in-google-colab-a-complete-34204f2d6ae2

So you’re getting to grips with Google Colab because you can’t wait to use it’s completely free GPU on this awesome free cloud service based on Jupyter Notebooks. Working with this fantastic tool has thrown some curveballs which I’ve had to research and then found an easier way to “skin this cat”. One of them was how to mount my Google Drive so I could access my data-files.

You’ve probably already read many articles which explains how to mount your Google Drive so I’ll just skim over this first…

Using the import statement:

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

Simply click on the blue link, select your Google e-mail address from the list and click on ‘Allow’. Copy the code (you can select the two overlapping rectangles to copy the code) and hit Ctrl + C (cmd + C on Mac) to copy it to the clipboard. Paste it into the ‘Enter your authorisation code:’ and you’re done.

Your Google Drive has been successfully mounted. Good, but Colab can do one better, using 3 mouse clicks and no code!

Firstly, click the folder icon at the bottom (hovering your mouse over this shows ‘Files’) of the list of icons on the left-hand-side

A message will appear stating ‘Connecting to a runtime to enable file browsing’:

Click on the right-most icon (hovering your mouse over this displays ‘Mount Drive’):

Click on ‘CONNECT TO GOOGLE DRIVE’

Your Google Drive should now show as being mounted:

Click on the folder ‘MyDrive’ to drill down into you Google Drive directory.

NOTE: You will have to perform this quick action action every time your runtime session ends.

--

--