Amanda Watson
Amanda Watson

Reputation: 370

How to mount a Google Shared Drive in Google Colaboratory?

I am working in Google Colaboratory. Until about a week ago, I was able to mount my shared drive using the following:

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

and then read a data file using:

data = pd.read_csv('/content/drive/Team Drives/TestProject/test.csv')

About a week ago, after they updated team drives to shared drives, that stopped working. How do I access my shared drive files now?

Upvotes: 8

Views: 14077

Answers (3)

hotheadhacker
hotheadhacker

Reputation: 182

This is the only simple solution that I found myself and is working like charm:

  • Step 1: mount google drive normally:
from google.colab import drive

drive.mount("/content/drive")

  • Step 2: while saving or fetching data from shared drive:

a) Writing Data to shared drive

!cp "//content/drive/Shareddrives/<shared_ drive_name>/my-video.mp4" "my-video.mp4"

b) Reading data from Shared Drive

!cat /content/drive/Shareddrives/<shared_ drive_name>/example.txt
#or
pd.read_csv("/content/drive/Shareddrives/<shared_ drive_name>/data_example.csv")

Note: If if it did not work try to changing name of share drive without spaces

Upvotes: 0

Nathan
Nathan

Reputation: 78439

As of 2022, it looks like the Shared Drive path is Shareddrives with no space. So:

drive.mount('/content/drive/') 
# /contents/drive/Shareddrive/Foo is now pointing to my Foo shared drive

Upvotes: 1

Amanda Watson
Amanda Watson

Reputation: 370

All that needed to be done was update "Team Drives" to "Shared drives".

Changing the code to this works:

data = pd.read_csv('/content/drive/Shared drives/TestProject/test.csv')

Upvotes: 4

Related Questions