【问题标题】:Download a Kaggle Dataset下载 Kaggle 数据集
【发布时间】:2021-01-04 08:43:39
【问题描述】:

我想下载一个 Kaggle 数据集。我生成了 Kaggle.json 文件,但不幸的是我没有驱动器(我不能使用它)。是否有任何选项可以直接在代码中生成用户名和令牌? 例如我试过这个

x =  '{"username":"<USERNAME>","key":"<TOKEN>"}'
y = json.loads(x)
api = KaggleApi(y)
api.authenticate()
files = api.competition_download_files("two-sigma-financial-news")

错误是

  ---------------------------------------------------------------------------
    OSError                                   Traceback (most recent call last)
    <ipython-input-6-237de0539a08> in <module>()
          1 api = KaggleApi(y)
    ----> 2 api.authenticate()
          3 files = api.competition_download_files("two-sigma-financial-news")
    
    /usr/local/lib/python3.6/dist-packages/kaggle/api/kaggle_api_extended.py in authenticate(self)
        164                 raise IOError('Could not find {}. Make sure it\'s located in'
        165                               ' {}. Or use the environment method.'.format(
    --> 166                                   self.config_file, self.config_dir))
        167 
        168         # Step 3: load into configuration!
    
        OSError: Could not find kaggle.json. Make sure it's located in /root/.kaggle. Or use the environment method.

但这是不对的。有人可以帮我吗?我正在使用 Colab,但我不想将 JSON 文件存储在我的 Google Drive 中。有没有直接生成JSON文件的选项?

提前致谢。

【问题讨论】:

    标签: python json kaggle


    【解决方案1】:

    也许这篇文章有帮助:https://www.kaggle.com/general/51898 它链接到这个脚本:

    # Info on how to get your api key (kaggle.json) here: https://github.com/Kaggle/kaggle-api#api-credentials
    !pip install kaggle
    api_token = {"username":"USERNAME","key":"API_KEY"}
    import json
    import zipfile
    import os
    with open('/content/.kaggle/kaggle.json', 'w') as file:
        json.dump(api_token, file)
    !chmod 600 /content/.kaggle/kaggle.json
    !kaggle config path -p /content
    !kaggle competitions download -c jigsaw-toxic-comment-classification-challenge
    os.chdir('/content/competitions/jigsaw-toxic-comment-classification-challenge')
    for file in os.listdir():
        zip_ref = zipfile.ZipFile(file, 'r')
        zip_ref.extractall()
        zip_ref.close()
    

    来自:https://gist.github.com/jayspeidell/d10b84b8d3da52df723beacc5b15cb27

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-08-29
      • 2019-12-09
      • 2021-09-05
      • 2020-04-28
      • 2021-07-24
      • 2020-01-20
      • 2019-03-31
      • 2023-03-26
      相关资源
      最近更新 更多