korakot / kora

Convenient tools for Colab
MIT License
269 stars 38 forks source link

No module named 'download' #15

Closed bmox closed 3 years ago

bmox commented 3 years ago

My code

folder_id="here_is_my_folder_id" 
from kora import drive
drive.download_folder(folder_id)

error:

/usr/local/lib/python3.7/dist-packages/kora/drive.py in download_folder(folder_id)
     60     urlretrieve(url, path)
     61     # recursive download
---> 62     import download
     63     download.download_folder(service, folder_id, './', folder_name)
     64     return folder_name

ModuleNotFoundError: No module named 'download'
alex-guer commented 3 years ago

It comes from the fact that in the function, the path is defined for Python 3.6 and colab upgraded to 3.7. Instead of using the library, try to use this function (the function from the library, but with the variable path updated)

from urllib.request import urlretrieve

def download_folder(folder_id):
    """ I copy this one from my old code, use drive API directly (not pydrive) """
    # authenticate
    from google.colab import auth
    auth.authenticate_user()
    # get folder_name
    from googleapiclient.discovery import build
    service = build('drive', 'v3')
    folder_name = service.files().get(fileId=folder_id).execute()['name']
    # install library 
    url = 'https://github.com/segnolin/google-drive-folder-downloader/raw/master/download.py'
    path = '/usr/local/lib/python3.7/dist-packages/download.py'
    urlretrieve(url, path)
    # recursive download
    import download
    download.download_folder(service, folder_id, './', folder_name)
    return folder_name