0

I want to unzip csv files downloaded from kaggle on google colab by code below. But every time I run the command unzip, it says there is no such file or directory found, whereas colab says files have been downloaded succesfully !

!pip install kaggle
from googleapiclient.discovery import build
import io, os
from googleapiclient.http import MediaIoBaseDownload
from google.colab import auth
auth.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', [])
# print(kaggle_api_key)
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 = False
while done is False:
    status, done = downloader.next_chunk()
    print("Download %d%%." % int(status.progress() * 100))
os.chmod(filename, 600)


!kaggle competitions download -c pubg-finish-placement-prediction
!chmod 600 /root/.kaggle/kaggle.json

!unzip train_V2.zip

Output : unzip: cannot find or open train_V2.zip, train_V2.zip.zip or train_V2.zip.ZIP.

Even unzip train_V2.csv.zip doeesn't work ! What am I doing wrong ?

Callmeat911 True
  • 203
  • 1
  • 2
  • 5

1 Answers1

0

In google colab they might erase all your data if you are reconnecting or changing the Runtime type. So be careful with your data.

Before you run the file you should check if the file exists. Try listing files using ls command. If the file does not exist try to place it again. If you are downloading it from the web you can use wget command.

Lahiru Karunaratne
  • 2,020
  • 16
  • 18