首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >下载Kaggle数据集

下载Kaggle数据集
EN

Stack Overflow用户
提问于 2020-09-17 20:44:45
回答 1查看 384关注 0票数 2

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

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

错误是

代码语言:javascript
复制
  ---------------------------------------------------------------------------
    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文件的选项?

提前谢谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-09-17 21:08:57

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

代码语言:javascript
复制
# 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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63938316

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档