Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error while importing Kaggle dataset on Colab

When executing the following lines,

!pip install kaggle
!kaggle competitions download -c dogs-vs-cats -p /content/

I got the following error messages,

Traceback (most recent call last):
File "/usr/local/bin/kaggle", line 7, in <module>
from kaggle.cli import main
File "/usr/local/lib/python3.6/dist-packages/kaggle/__init__.py", line 23, in <module>
api.authenticate()
File "/usr/local/lib/python3.6/dist-packages/kaggle/api/kaggle_api_extended.py", line 109, in authenticate
self._load_config(config_data)
File "/usr/local/lib/python3.6/dist-packages/kaggle/api/kaggle_api_extended.py", line 151, in _load_config
raise ValueError('Error: Missing %s in configuration.' % item)
ValueError: Error: Missing username in configuration.

I don't know what just happened...same lines just worked fine before. It's the first time I found this problem.

like image 900
Alan.L Avatar asked Aug 22 '18 00:08

Alan.L


People also ask

How do I import using kaggle datasets in Google Colab?

Step 1: Visit the Kaggle website and Select the Dataset tab. Step 2: Select any Dataset and Click on the Download. Step 3: The downloaded file will be in Zip form, Unzip it. Step 4: Upload Your Dataset file or folder to Google Colab Notebook.

How do I import a dataset in Google Colab?

It is the easiest way to upload a CSV file in Colab. For this go to the dataset in your GitHub repository, and then click on “View Raw”. Copy the link to the raw dataset and pass it as a parameter to the read_csv() in pandas to get the dataframe.


2 Answers

It suddenly stopped working here as well. Apparently, the kaggle api was not searching the kaggle.json file in the correct place. Since I was using the kaggle api inside a colab notebook, I was importing the kaggle.json like this:

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', [])

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)

It worked just fine. But now, the kaggle api searches the kaggle.json in this location:

~/.kaggle/kaggle.json

So, I just had to move/copy the file I downloaded to the right place:

!mkdir ~/.kaggle
!cp /content/.kaggle/kaggle.json ~/.kaggle/kaggle.json

And it started working again.

like image 54
Edhowler Avatar answered Oct 21 '22 05:10

Edhowler


This simple thing did it for me on Google Cola.

!echo '{"username":"USERNAME","key":"KEY"}' > ~/.kaggle/kaggle.json
!kaggle datasets download -d mmoreaux/environmental-sound-classification-50

--

edit, might have changed to:

!echo '{"username":"USERNAME","key":"KEY"}' > /root/.kaggle/kaggle.json
!kaggle datasets download -d mmoreaux/environmental-sound-classification-50
like image 25
Marc Moreaux Avatar answered Oct 21 '22 06:10

Marc Moreaux