它突然也停止在这里工作。显然,kaggle api没有在正确的位置搜索kaggle.json文件。由于我在colab笔记本中使用kaggle
api,因此我要像这样导入kaggle.json:
from googleapiclient.discovery import buildimport io, osfrom googleapiclient.http import MediaIobaseDownloadfrom google.colab import authauth.authenticate_user()drive_service = build('drive', 'v3')results = drive_service.files().list( q="name = 'kaggle.json'", fields="files(id)").execute()kaggle_api_key = results.get('files', [])filename = "/content/.kaggle/kaggle.json"os.makedirs(os.path.dirname(filename), exist_ok=True)request = drive_service.files().get_media(fileId=kaggle_api_key[0]['id'])fh = io.FileIO(filename, 'wb')downloader = MediaIobaseDownload(fh, request)done = Falsewhile done is False: status, done = downloader.next_chunk() print("Download %d%%." % int(status.progress() * 100))os.chmod(filename, 600)
工作正常。但是现在,kaggle api在以下位置搜索kaggle.json:
~/.kaggle/kaggle.json
因此,我只需要将下载的文件移动/复制到正确的位置:
!mkdir ~/.kaggle!cp /content/.kaggle/kaggle.json ~/.kaggle/kaggle.json
然后它又开始工作了。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)