Kaggle json

I was trying to replicate the Notebook 9 and I got this message in Paperspace,

OSError                                   Traceback (most recent call last)
<ipython-input-3-84bf1621b01a> in <module>
      1 #hide
      2 from utils import *
----> 3 from kaggle import api
      4 from pandas.api.types import is_string_dtype, is_numeric_dtype, is_categorical_dtype
      5 from fastai2.tabular.all import *

/opt/conda/envs/fastai/lib/python3.7/site-packages/kaggle/__init__.py in <module>
     21 
     22 api = KaggleApi(ApiClient())
---> 23 api.authenticate()

/opt/conda/envs/fastai/lib/python3.7/site-packages/kaggle/api/kaggle_api_extended.py in authenticate(self)
    147                 raise IOError('Could not find {}. Make sure it\'s located in'
    148                               ' {}. Or use the environment method.'.format(
--> 149                                   self.config_file, self.config_dir))
    150 
    151         # Step 3: load into configuration!

OSError: Could not find kaggle.json. Make sure it's located in /root/.kaggle. Or use the environment method.


**OSError: Could not find kaggle.json. Make sure it's located in /root/.kaggle. Or use the environment method.**

and I can’t create other folders in Paperspace at the moment. I get this error:
Unexpected error while saving file: storage/course-v4/nbs/Untitled Folder [Errno 28] No space left on device: '/notebooks/storage/course-v4/nbs/Untitled Folder’

1 Like

Did you download the Kaggle API token, the Kaggle.json file with your credentials and place it in the ~/.kaggle/ directory? That should fix it.

The notebook does it in a different way by specifying the credentials directly in the notebook. Both should work.

2 Likes

where is the ~/.kaggle directory in Paperspace?

Just install the Kaggle api (!pip install kaggle) and download your Kaggle.json file and place it in the root directory which should already be created ‘~/.kaggle/’.

1 Like

Are you familiar with Linux? You should be able to access the filesystem using: !ls

1 Like

Jupyter allows you to conviniently upload files, I uploaded mine, switched to terminal and then mv kaggle.json ~/.kaggle/kaggle.json

3 Likes

I had the same issue using paperspace. What I ended up doing is uploading my kaggle.json file to my personal github branch and then on paperspace jupyter terminal, I did a git pull to download it to the paperspace. Then I copied it to the /root/kaggle directory on paperspace using the jupyter terminal. That worked, but now I’m getting another import error:

ModuleNotFoundError Traceback (most recent call last)
in
6 from sklearn.ensemble import RandomForestRegressor
7 from sklearn.tree import DecisionTreeRegressor
----> 8 from dtreeviz.trees import *
9 from IPython.display import Image, display_svg, SVG
10

ModuleNotFoundError: No module named ‘dtreeviz’

2 Likes

I had the same import error. In another cell I pip installed dtreeviz to get it working.

!pip install dtreeviz

3 Likes

I never worked with kaggle.json file, I always do:

import os
kaggle_data={"username":"","key":""}
os.environ['KAGGLE_USERNAME']=kaggle_data["username"]
os.environ['KAGGLE_KEY']=kaggle_data["key"]

Enter you details in the corresponding fields and it works.
PS: import kaggle after running this cell

9 Likes

The solution is actually given in that notebook itself.

cred= ‘{username=’’, key=’’}’
cred_path = Path(’~/.kaggle/kaggle.json’).expanduser()
if not cred_path.exists():
cred_path.parent.mkdir(exist_ok=True)
cred_path.write_text(creds)
cred_path.chmod(0o600)

This should create that the missing file.

2 Likes

In kaggle:

I uploaded the file copied the location (which was …/input/kagglejson/kaggle.json) and put in a cell (as suggested above)

!mkdir ~/.kaggle
!cp ../input/kagglejson/kaggle.json ~/.kaggle/kaggle.json

Kaggle suggests running

!chmod 600 /root/.kaggle/kaggle.json

So the file is not viewable by others

All between the two different import cells