1

I was using google colab and using this code to access my google drive:

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

It works well but the authentification doesn't last long and I don't want to re-enter my credentials all the time. So I tried to use Pydrive to save my credentials to a file (using this answer):

!pip install pydrive
from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
from google.colab import auth
from oauth2client.client import GoogleCredentials

gauth = GoogleAuth()
gauth.LoadCredentialsFile("mycreds.txt")
gauth.Authorize()
drive = GoogleDrive(gauth)

but I can only write files remotely with this solution, and I would like to be able to mount my google drive entirely so that I can easily use unix commands. Is there a way to do that?

Sulli
  • 763
  • 1
  • 11
  • 33

2 Answers2

2

PyDrive doesn't create a FUSE mount, so doesn't work for you intended purpose.

Authentication of drive.mount() should last the lifetime of the assigned VM, and no option is going to outlast a VM's assignment, so I don't think what you want is possible today.

Ami F
  • 2,202
  • 11
  • 19
-2

I am looking for answer for this too, and it appears that most easiest way to achieve it is that using colab pro version. you can find more info here

ikel
  • 1,790
  • 6
  • 31
  • 61
  • There isn't any info pointing that Colab Pro has any different language features than the standard ones (the pro benefits are hardware related). – Diego Queiroz Aug 03 '20 at 01:40
  • @DiegoQueiroz The author has issue with remain in session without keeping authenticating himself. he did not ask about language features at all ! . what he wanted is a feature is only provided by pro version. better hardware is not the only thing pro version offers! – ikel Aug 15 '20 at 03:20
  • Actually, he asks about mounting PyDrive as a Unix Drive (this is the title). The point about keeping the authentication session was just an introduction, to contextualize the question. According to him, he is solving this problem with PyDrive, since it allows him to store credentials in a file. – Diego Queiroz Aug 16 '20 at 10:56
  • authentication session does not last, that's the problem! because of that problem, author is trying pydrive, then it does not satisfy his needs, colab pro version does provide function that fix his original root issue which is authentication does not maintain as well as "mount my google drive entirely" issue pydrive does not provide which is also his problem asked in question, so I don't see where my answer does not relate to the point. – ikel Aug 17 '20 at 17:09
  • "... authentification doesn't last long **AND** I don't want to re-enter my credentials all the time". Your answer try to solve the first problem, but leaves the second unattended. Even if his session lasts longer, he will still need to enter his credentials all the time (every day, at least). He didn't provide any parameter to allow us determine if 24h running would be enough (my guess: because this is not the problem). By the definition of the AND operator, I feel he just don't want to enter his credentials all the time, and not that he wants to make his sessions last longer. – Diego Queiroz Aug 19 '20 at 04:56
  • But if you still think your solution is ok, maybe you can clarify your answer with something like "*If the standard `google.colab.drive` library solves your problem, and you just want your sessions last longer, you may want to have a look into the Colab Pro (paid version). It allows you to keep your sessions for up to 24h, but you'll still need to enter your credentials every day.*". The way your answer is currently written made me search the web for language features that were supposed to be only available in Colab Pro, although there aren't any. – Diego Queiroz Aug 19 '20 at 05:04