file download from google drive to colaboratory

后端 未结 7 2144
遇见更好的自我
遇见更好的自我 2021-02-05 12:22

I was trying to download file from my google drive to colaboratory.

file_id = \'1uBtlaggVyWshwcyP6kEI-y_W3P8D26sz\'

import io
from googleapiclient.http import M         


        
7条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-05 12:57

    Step 1

    !pip install -U -q PyDrive
    

    Step 2

    from pydrive.auth import GoogleAuth
    from pydrive.drive import GoogleDrive
    from google.colab import auth
    from oauth2client.client import GoogleCredentials
    # Authenticate and create the PyDrive client.
    # This only needs to be done once per notebook.
    auth.authenticate_user()
    gauth = GoogleAuth()
    gauth.credentials = GoogleCredentials.get_application_default()
    drive = GoogleDrive(gauth)
    

    Step3

    file_id = '17Cp4ZxCYGzWNypZo1WPiIz20x06xgPAt' # URL id. 
    downloaded = drive.CreateFile({'id': file_id})
    downloaded.GetContentFile('shaurya.txt')
    

    Step4

    !ls #to verify content
    

    OR

    import os
    print(os.listdir())
    

提交回复
热议问题