Setting environment variables in Google Colab

If you like %magic, you can also use %env to make it a bit shorter.

%env KAGGLE_USERNAME=abcdefgh

If the value is in a variable you can also use

%env KAGGLE_USERNAME=$username

I think you want to do something like:

import os
os.environ['KAGGLE_USERNAME'] = ...
os.environ['KAGGLE_KEY'] = ...

The reason is that !export will assign the environment variable in an ephemeral sub-shell. But, you want to update the environment for the Python subprocess that spawns those sub-shells.

enter image description here