Skip to content

Environment Method #550

@stefanwerleman

Description

@stefanwerleman

This is for the environment method mentioned in here:

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

I read your logic for reading environment variables in case ~/.kaggle/kaggle.json does not exist. I suggest you first load the environments variable using python-dotenv before using os.environ to extract the variable names that start with KAGGLE_.

The moment someone imports kaggle in their project, your __init__.py script is immediately executed, which, in turn, attempts to read the environment variables before the .env is even loaded. This means the line if key.startwith("KAGGLE_"): in theread_config_environment() method will always return False even if the developer already has an .env file with the correct varaibles.

Here's is a snippet of my suggestion for /kaggle/__init_.py:

# coding=utf-8
import dotenv

# Load environment variables for the read_config_environment() method
dotenv.load_dotenv()

from __future__ import absolute_import
from kaggle.api.kaggle_api_extended import KaggleApi
from kaggle.api_client import ApiClient

api = KaggleApi(ApiClient())
api.authenticate()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions