I was just running through this process and thought it might be helpful for others:
What to do in Kaggle:
Step 1. Go to your Kaggle account next to Discussion and click the … and then Account.
Step 2. Scroll to API and click Create New API Token and a kaggle.json file will download.
What to do in Google Colab:
Step 3. Open a new Colab file
Step 4:
! pip install -q kaggle
Step 5:
add the following code:
from google.colab import files
files.upload()
Click choose files and upload the kaggle.json file
Step 6:
add the following code:
! mkdir ~/.kaggle
! cp kaggle.json ~/.kaggle/
Step 7:
add the following code:
! chmod 600 ~/.kaggle/kaggle.json
Step 8:
I prefer to actually mount Google Drive to put the files in the folders I want so I use this command:
from google.colab import drive
drive.mount(‘/content/gdrive’, forceremount=True) rootdir = “/content/gdrive/My Drive/”
You will have to accept and copy the auth code and paste that back into your notebook.
Step 9:
I prefer to CD into the folder I want to put my data into:
%cd ./gdrive/’My Drive’/[add drive here]
pwd
(this will confirm the directory you are in)
Step 10:
Download data by going to the competition you are working on and go to data. There you will see a line of code that says API. Like below:
! kaggle competitions download -c ‘name-of-competition’
I’m entering the Wheat one so this is the line (add ! and space before it):
! kaggle competitions download -c global-wheat-detection
For fastai2 in colab:
Add the following code to import:
!pip install fastai2
For vision run:
from fastai2.vision.all import *