Getting the Kaggle CLI working without the usual headaches
Doing Kaggle from the terminal instead of clicking around the website is so much nicer once it’s set up, but the first-time setup has a couple of spots that trip everyone (me included). Here’s the whole thing, including the errors you’ll probably hit.
Install it
pip install kaggleThat gives you the
kagglecommand for pulling data, submitting predictions, and browsing competitions without leaving the terminal.Hook up your credentials
- Log in at kaggle.com/settings
- Find the API section and click Create New Token
- A
kaggle.jsonfile downloads. That’s your credentials, so don’t commit it anywhere. - Move it where the CLI expects:
- Linux/macOS:
~/.kaggle/kaggle.json - Windows:
C:\Users\<username>\.kaggle\kaggle.json
- Linux/macOS:
- On Linux/macOS, lock down the permissions:
chmod 600 ~/.kaggle/kaggle.json
The commands you’ll actually use
Command What it does kaggle competitions listBrowse active competitions kaggle competitions download -c titanicDownload competition data kaggle competitions submit -c titanic -f submission.csv -m "message"Submit predictions kaggle competitions submissions -c titanicSee your submission history kaggle datasets list -s "keyword"Search public datasets When it breaks (and it will, once)
- “Could not find kaggle.json”: the file isn’t in
~/.kaggle/(or%USERPROFILE%\.kaggle\on Windows). That’s almost always it. - “403 Forbidden”: you haven’t accepted the competition rules on the website yet. Go click the button, then try again.
- “401 Unauthorized”: your API token expired or got revoked. Regenerate it and swap in the new
kaggle.json. - Timeouts: usually just the Kaggle API having a slow moment. Check your connection and retry.
If you want to confirm everything’s wired up, run
python scripts/verify_kaggle_cli.pyand it’ll check the setup for you.