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()
This is for the environment method mentioned in here:
I read your logic for reading environment variables in case
~/.kaggle/kaggle.json
does not exist. I suggest you first load the environments variable usingpython-dotenv
before usingos.environ
to extract the variable names that start withKAGGLE_
.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 lineif key.startwith("KAGGLE_"):
in theread_config_environment()
method will always returnFalse
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
: